zsh: fix PATH manipulation on MacOS
My previous fix for /usr/libexec/path_helper messing with the PATH was no longer working because zsh sources /etc/zprofile (which on MacOS executes path_helper) AFTER $HOME/.zshenv, thus overwriting my changes.
This commit is contained in:
parent
38f286411d
commit
e994d8f0e3
4 changed files with 73 additions and 49 deletions
|
@ -53,6 +53,7 @@ stow_packages() {
|
|||
nvim \
|
||||
python \
|
||||
readline \
|
||||
shell \
|
||||
ssh \
|
||||
tmux \
|
||||
x11 \
|
||||
|
|
58
shell/.config/shell/path.sh
Normal file
58
shell/.config/shell/path.sh
Normal file
|
@ -0,0 +1,58 @@
|
|||
# This file is meant to be sourced from either $ZDOTDIR/.zshenv or
|
||||
# $ZDOTDIR/.zshrc (see those files for explanation).
|
||||
|
||||
# Prevent path_helper from messing with the PATH when starting tmux.
|
||||
#
|
||||
# Clearing PATH before path_helper executes (from /etc/profile) will prevent it
|
||||
# from prepending the default PATH to our (previously) chosen PATH, and will
|
||||
# allow the rest of this file to set up PATH and MANPATH correctly.
|
||||
#
|
||||
# For details see: https://superuser.com/a/583502
|
||||
#
|
||||
[ "$(uname -s)" = "Darwin" ] && { PATH=""; source /etc/profile; }
|
||||
|
||||
# Add custom bin dirs to PATH if they exist and are not already in PATH.
|
||||
while read -r dir; do
|
||||
case ":${PATH:=$dir}:" in
|
||||
*:"$dir":*) ;;
|
||||
*) PATH="$dir:$PATH" ;;
|
||||
esac
|
||||
done <<EOL
|
||||
$LOCAL_PREFIX/bin
|
||||
$LOCAL_PREFIX/opt/findutils/libexec/gnubin
|
||||
$HOME/.local/bin
|
||||
EOL
|
||||
export PATH
|
||||
|
||||
# Prepend custom man directories to MANPATH if they exist, so that we get
|
||||
# correct man page entries when multiple versions of a command are
|
||||
# available.
|
||||
command -v manpath >/dev/null 2>&1 && MANPATH="$(unset MANPATH; manpath)"
|
||||
while read -r dir; do
|
||||
case ":${MANPATH:=$dir}:" in
|
||||
*:"$dir":*) ;;
|
||||
*) MANPATH="$dir:$MANPATH" ;;
|
||||
esac
|
||||
done <<EOL
|
||||
$LOCAL_PREFIX/share/man
|
||||
$LOCAL_PREFIX/opt/findutils/libexec/gnuman
|
||||
$HOME/.local/share/man
|
||||
EOL
|
||||
export MANPATH
|
||||
|
||||
unset dir
|
||||
|
||||
# These checks habe to be done after PATH manipulation above so we can find
|
||||
# installed programs if they are in the added paths.
|
||||
|
||||
if command -v nvim >/dev/null 2>&1; then
|
||||
export EDITOR="nvim"
|
||||
else
|
||||
export EDITOR="vim"
|
||||
fi
|
||||
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
export HOMEBREW_NO_ANALYTICS=1
|
||||
export HOMEBREW_NO_AUTO_UPDATE=1
|
||||
fi
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
#!/bin/zsh
|
||||
# Set up zsh for interactive use (options, prompt, aliases, etc.)
|
||||
|
||||
# On MacOS, manipulate PATH and MANPATH here (see explanation in .zshenv).
|
||||
[ "$(uname -s)" = "Darwin" ] && source "$XDG_CONFIG_HOME/shell/path.sh"
|
||||
|
||||
# Source additional configurations if available.
|
||||
while read -r f; do [ -f "$f" ] && source "$f"; done <<EOL
|
||||
$ZDOTDIR/aliases
|
||||
|
|
60
zsh/.zshenv
60
zsh/.zshenv
|
@ -36,53 +36,15 @@ export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
|
|||
unset rst
|
||||
}
|
||||
|
||||
# Prevent path_helper from messing with the PATH when starting tmux.
|
||||
# See: https://superuser.com/a/583502
|
||||
[ "$(uname -s)" = "Darwin" ] && { PATH=""; source /etc/profile; }
|
||||
|
||||
# Add custom bin dirs to PATH if they exist and are not already in PATH.
|
||||
while read -r dir; do
|
||||
case ":${PATH:=$dir}:" in
|
||||
*:"$dir":*) ;;
|
||||
*) PATH="$dir:$PATH" ;;
|
||||
esac
|
||||
done <<EOL
|
||||
$LOCAL_PREFIX/opt/findutils/libexec/gnubin
|
||||
$LOCAL_PREFIX/bin
|
||||
$HOME/.local/bin
|
||||
EOL
|
||||
export PATH
|
||||
|
||||
# Prepend custom man directories to MANPATH if they exist, so that we get
|
||||
# correct man page entries when multiple versions of a command are
|
||||
# available.
|
||||
command -v manpath >/dev/null 2>&1 && MANPATH="$(unset MANPATH; manpath)"
|
||||
while read -r dir; do
|
||||
case ":${MANPATH:=$dir}:" in
|
||||
*:"$dir":*) ;;
|
||||
*) MANPATH="$dir:$MANPATH" ;;
|
||||
esac
|
||||
done <<EOL
|
||||
$LOCAL_PREFIX/opt/findutils/libexec/gnuman
|
||||
$LOCAL_PREFIX/share/man
|
||||
$HOME/.local/share/man
|
||||
EOL
|
||||
export MANPATH
|
||||
|
||||
unset dir
|
||||
|
||||
# These checks habe to be done after PATH manipulation above so we can find
|
||||
# installed programs if they are in the added paths.
|
||||
|
||||
if command -v nvim >/dev/null 2>&1; then
|
||||
export EDITOR="nvim"
|
||||
else
|
||||
export EDITOR="vim"
|
||||
fi
|
||||
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
LOCAL_PREFIX="$(brew --prefix)"
|
||||
export HOMEBREW_NO_ANALYTICS=1
|
||||
export HOMEBREW_NO_AUTO_UPDATE=1
|
||||
fi
|
||||
# Add custom directories to PATH and MANPATH.
|
||||
#
|
||||
# On MacOS, we skip it here because these relevant files are sourced in order
|
||||
# by zsh on startup ($ZDOTDIR defaults to $HOME if not set):
|
||||
#
|
||||
# $ZDOTDIR/.zshenv <-- This file.
|
||||
# /etc/zprofile <-- On MacOS this sources /usr/libexec/path_helper,
|
||||
# which would undo what we do here.
|
||||
# $ZDOTDIR/.zshrc <-- So we defer our PATH manipulation to this file.
|
||||
#
|
||||
[ "$(uname -s)" = "Darwin" ] || source "$XDG_CONFIG_HOME/shell/path.sh"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue