Last active
August 29, 2015 14:06
-
-
Save dol/9070a557f6e3c2012eff to your computer and use it in GitHub Desktop.
cd a file fix
This file contains 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
# Never cd a file and get the warning it's no a directory | |
# Important to unset the variable for ZSH prompt | |
function cd() { | |
FORWARD_ARGS=() | |
for ARG in "$@" | |
do | |
case "$ARG" in | |
-L) FORWARD_ARGS+=("-L") | |
;; | |
-P) FORWARD_ARGS+=("-P") | |
;; | |
*) if [ ! -d "$ARG" ]; then | |
FORWARD_ARGS+=$(dirname $ARG); | |
else | |
FORWARD_ARGS+=$ARG | |
fi | |
;; | |
esac | |
done | |
unset ARG | |
builtin cd $FORWARD_ARGS | |
unset FORWARD_ARGS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment