From ed8619e0abe7aa147828b3b7568b24a3070b9094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 5 Oct 2015 01:43:32 +0200 Subject: [PATCH] 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 --- zshenv | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/zshenv b/zshenv index b4461af881..283cfec6fd 100644 --- a/zshenv +++ b/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 <&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