[issue-206] rvmrc should get sourced on cd; over version managers may also override cdpwd hooks, so provide a way to support hooks; fixes #206

pull/467/head
Ivan Povalyukhin 2015-05-06 20:39:44 -07:00
parent 829716276b
commit fb676b973f
1 changed files with 19 additions and 5 deletions

View File

@ -32,14 +32,28 @@ autoenv_init()
done done
} }
cd() # Bash support for Zsh like chpwd hook
[[ -n "${ZSH_VERSION:-}" ]] || { cd() { __zsh_like_cd cd "$@" ; } }
__zsh_like_cd()
{ {
if builtin cd "$@" \typeset __zsh_like_cd_hook
if
builtin "$@"
then then
autoenv_init shift || true # remove the called method
return 0 for __zsh_like_cd_hook in chpwd "${chpwd_functions[@]}"
do
if \typeset -f "$__zsh_like_cd_hook" >/dev/null 2>&1
then "$__zsh_like_cd_hook" "$@" || break # finish on first failed hook
fi
done
true
else else
echo "else?"
return $? return $?
fi fi
} }
[[ -n "${chpwd_functions}" ]] || { export -a chpwd_functions; } # define hooks as shell array
[[ " ${chpwd_functions[*]} " == *" autoenv_init "* ]] || # prevent double addition
chpwd_functions+=(autoenv_init) # add hook to the list