From 85292e5ea6e3b6e738bddd67512e1182530a0d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 12 Feb 2026 10:29:45 +0100 Subject: [PATCH] Fix initial setup on `omz trace on` --- lib/cli.zsh | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 3088707e7..81871eb6b 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -919,7 +919,50 @@ EOF } function _omz::trace::on { - 'builtin' ':' > "${OMZ_TRACES}/.enabled" + # Check that .zshenv hook is added + if [[ ! -f "$HOME/.zshenv" ]]; then + touch "$HOME/.zshenv" + chmod u+rw "$HOME/.zshenv" + fi + + # Check that hook is sourced in .zshenv + # + # 1. Compute the hook path relative to $HOME + local hook_path="$ZSH/hooks/zshenv.zsh" + hook_path="${hook_path/#$HOME\//\$HOME/}" + + # 2. Compute the source command + local hook_source=". \"$hook_path\"" + + # 3. Check if already added to .zshenv, otherwise add it + if ! command grep -Fq "$hook_source" "$HOME/.zshenv"; then + # 4. If not, prepend the hook source command + local tmpfile==(:) + cat - "$HOME/.zshenv" >| "$tmpfile" <