diff --git a/zshenv b/zshenv index 64db438..8b8b096 100644 --- a/zshenv +++ b/zshenv @@ -2,9 +2,27 @@ # ZSH Environment Setup # -# Ensure values in path variable are unique. +# Ensure values in path variable are unique typeset -U path +# Prevent loading ZSH startup from files /etc on macOS. The /etc/zprofile file +# screws around with PATH, so we want to avoid it, and instead manually load the +# files we care about. +if [[ "$OSTYPE" == "darwin"* ]]; then + # Disable loading startup files from /etc + unsetopt GLOBAL_RCS + + # Setup default PATH just like /etc/zprofile does + if [ -x "/usr/libexec/path_helper" ]; then + eval `/usr/libexec/path_helper -s` + fi + + # Load /etc/zshenv if it exists + if [ -f "/etc/zshenv" ]; then + source "/etc/zshenv"; + fi +fi + # Path helpers path_list () { print -l "${(@)path}" @@ -49,10 +67,10 @@ if [[ "$TMPDIR" == "/var/folders/"* ]] || [[ "$TMPDIR" == "" ]]; then mkdir -p "$TMPDIR" fi -# Ensure basic systems paths are in desired order. +# Ensure basic systems paths are in desired order path_prepend "/sbin" -path_prepend "/bin" path_prepend "/usr/sbin" +path_prepend "/bin" path_prepend "/usr/bin" path_prepend "/usr/local/sbin" path_prepend "/usr/local/bin" diff --git a/zshrc b/zshrc index 3a9c34e..7bab70f 100644 --- a/zshrc +++ b/zshrc @@ -2,9 +2,11 @@ # Z-Shell Init # -# Fix PATH re-ordering done by macOS, by loading ~/.zshenv again. -if [[ "$(uname)" == "Darwin" ]] && [ -x "/usr/libexec/path_helper" ]; then - source "$HOME/.zshenv" +# In our zshenv file we have on macOS disabled loading ZSH startup files from +# /etc to avoid /etc/zprofile messing up our carefully constructed PATH. So we +# need to manually load the other files we care about. +if [[ "$OSTYPE" == "darwin"* ]] && [ -f "/etc/zshrc" ]; then + source "/etc/zshrc"; fi @@ -75,8 +77,8 @@ fpath=("$DOTZSH/completion" "${fpath[@]}") source "$DOTZSH/aliases.zsh" # OS specific -if [[ "$(uname)" == "Darwin" ]]; then source "$DOTZSH/macos.zsh"; fi -if [[ "$(uname)" == "Linux" ]]; then source "$DOTZSH/linux.zsh"; fi +if [[ "$OSTYPE" == "darwin"* ]]; then source "$DOTZSH/macos.zsh"; fi +if [[ "$OSTYPE" == "linux"* ]]; then source "$DOTZSH/linux.zsh"; fi # Utils source "$DOTZSH/emacs.zsh"