Skip to content

Commit ed8619e

Browse files
mislavGeoff Harcourt
authored andcommitted
Detect if ~/.zshenv.local changes PATH and suggest .zshrc instead
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
1 parent 6c0a559 commit ed8619e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

zshenv

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1+
local _old_path="$PATH"
2+
13
# Local config
24
[[ -f ~/.zshenv.local ]] && source ~/.zshenv.local
5+
6+
if [[ $PATH != $_old_path ]]; then
7+
# `colors` isn't initialized yet, so define a few manually
8+
typeset -AHg fg fg_bold
9+
fg[red]=$'\e[31m'
10+
fg_bold[white]=$'\e[1;37m'
11+
reset_color=$'\e[m'
12+
13+
cat <<MSG >&2
14+
${fg[red]}Warning:${reset_color} your \`~/.zshenv.local' configuration seems to edit PATH entries.
15+
Please move that configuration to \`.zshrc.local' like so:
16+
${fg_bold[white]}cat ~/.zshenv.local >> ~/.zshrc.local && rm ~/.zshenv.local${reset_color}
17+
18+
(called from ${(%):-%N:%i})
19+
20+
MSG
21+
fi
22+
23+
unset _old_path

0 commit comments

Comments
 (0)