scatterd-dotfiles/hooks/post-up
Geoff Harcourt 06197218c7 Don't rely on Bash in post-up hook
In 16219a31db we implemented a post-up
hook that checked for a problematic `/etc/zshenv` file. OSX/macOS has
changed the file responsible for executing `path_helper` and loading the
system paths multiple times, and this script change issued a warning to
users if `path_helper` might be called in such a way that their paths
could be unexpectedly reordered.

The script used colored output to highlight this problem for the user,
and relied on Bash's script path introspection (through `$BASH_SOURCE`)
to print the location of the `post-up` hook to assist the user in
troubleshooting and understanding where our warning came from.

This change removes the hook's reliance on GNU Bash in favor of `sh`. It
uses the POSIX-compliant `$0` to determine the hook location (this
method is less robust than Bash's `$BASH_SOURCE`, but is available in
all POSIX shells) and removes colored output in the warning to be
compatible with shells that don't support colored output.

Fix #517.
2017-05-08 16:06:01 -04:00

26 lines
744 B
Bash
Executable file

#!/bin/sh
touch "$HOME"/.psqlrc.local
if [ ! -e "$HOME"/.vim/autoload/plug.vim ]; then
curl -fLo "$HOME"/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
fi
vim -u "$HOME"/.vimrc.bundles +PlugInstall +PlugClean! +qa
reset -Q
# detect old OS X broken /etc/zshenv and suggest rename
if grep -qw path_helper /etc/zshenv 2>/dev/null; then
dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
cat <<MSG >&2
Warning: \`/etc/zshenv' configuration file on your system may cause unexpected
PATH changes on subsequent invocations of the zsh shell. The solution is to
rename the file to \`zprofile':
sudo mv /etc/{zshenv,zprofile}
(called from ${dir}/post-up:${LINENO})
MSG
fi