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
This commit is contained in:
parent
6c0a559afd
commit
ed8619e0ab
1 changed files with 21 additions and 0 deletions
21
zshenv
21
zshenv
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue