Skip to content

Commit

Permalink
Detect if ~/.zshenv.local changes PATH and suggest .zshrc instead
Browse files Browse the repository at this point in the history
Warn people who might have PATH and similar configuration in their
`~/.zshenv.local` that they should upgrade to `~/.zshrc.local` since
that's a much better phase for such configuration. This is for backwards
compatibility with people's personal configurations from pre-El Capitan
days.

The generic `.zshenv` file from zsh distribution[1] advises:

> .zshenv is sourced on ALL invocations of the shell, unless the -f
> option is set. It should NOT normally contain commands to set the
> command search path, or other common environment variables unless you
> really know what you're doing. E.g. running `PATH=/custom/path gdb program`
> sources this file (when gdb runs the program via $SHELL), so you want
> to be sure not to override a custom environment in such cases. Note
> also that .zshenv should not contain commands that produce output or
> assume the shell is attached to a tty.

[1]: http://sourceforge.net/p/zsh/code/ci/master/tree/StartupFiles/zshenv
  • Loading branch information
mislav authored and Geoff Harcourt committed Oct 23, 2015
1 parent 6c0a559 commit ed8619e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions zshenv
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
local _old_path="$PATH"

# Local config
[[ -f ~/.zshenv.local ]] && source ~/.zshenv.local

if [[ $PATH != $_old_path ]]; then
# `colors` isn't initialized yet, so define a few manually
typeset -AHg fg fg_bold
fg[red]=$'\e[31m'
fg_bold[white]=$'\e[1;37m'
reset_color=$'\e[m'

cat <<MSG >&2
${fg[red]}Warning:${reset_color} your \`~/.zshenv.local' configuration seems to edit PATH entries.
Please move that configuration to \`.zshrc.local' like so:
${fg_bold[white]}cat ~/.zshenv.local >> ~/.zshrc.local && rm ~/.zshenv.local${reset_color}
(called from ${(%):-%N:%i})
MSG
fi

unset _old_path

0 comments on commit ed8619e

Please sign in to comment.