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" <