Skip to content

Instantly share code, notes, and snippets.

@dol
Last active August 29, 2015 14:06
Show Gist options
  • Save dol/9070a557f6e3c2012eff to your computer and use it in GitHub Desktop.
Save dol/9070a557f6e3c2012eff to your computer and use it in GitHub Desktop.
cd a file fix
# 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