Last active
August 29, 2015 14:20
-
-
Save joshenders/f0c0cba5187eba1bc790 to your computer and use it in GitHub Desktop.
rvm/extras/bash_zsh_support/chpwd/function.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__zsh_like_cd() | |
{ | |
# Called as: | |
# cd() { __zsh_like_cd cd "$@" ; } | |
# popd() { __zsh_like_cd popd "$@" ; } | |
# pushd() { __zsh_like_cd pushd "$@" ; } | |
# So, "$@" in __zsh_like_cd contains the __zsh_like_cd "personality" as well as passed arguments | |
\typeset __zsh_like_cd_hook # define local variable in __zsh_like_cd scope, may be POSIXly correct but lol- #! is /bin/bash, use "local __zsh_like_cd_hook". Also, hilarious that they prepend \ to typeset because who knows if you can trust that it's not hooked! | |
if | |
builtin "$@" # builtin returns true if command is a built-in | |
then | |
shift || true # remove the called "personality", such as cd, pushd, or popd | |
for __zsh_like_cd_hook in chpwd "${chpwd_functions[@]}" # no idea where chpwd is defined, git grep "function chpwd" returns nothing. Apparently this means something in zsh but this is definitely supposed to executed with bash, in fact, this whole function is hacking a zsh feature into bash | |
do | |
if \typeset -f "$__zsh_like_cd_hook" >/dev/null 2>&1 # if the hooked binary is a shell function | |
then "$__zsh_like_cd_hook" "$@" || break # call each hooked shell function with passed arguments and break on first failed function call | |
fi | |
done | |
true # override return value of last hooked shell function | |
else | |
return $? # return value of $(builtin "$@") for some reason | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment