Skip to content

Instantly share code, notes, and snippets.

@romanskie
Last active January 7, 2020 09:56
Show Gist options
  • Save romanskie/3ddf0be75bde55ba7d085e96130c8643 to your computer and use it in GitHub Desktop.
Save romanskie/3ddf0be75bde55ba7d085e96130c8643 to your computer and use it in GitHub Desktop.
bash alias that allows to pass files or dirs to the unix cd comand
# pass files or dirs to cd
cd_ () {
if [[ -d ${1} ]]; then
#echo ${1} is a directory"
cd ${1}
elif [[ -f ${1} ]]; then
#echo ${1} is a file"
cd $(dirname "${1}")
else
#echo ${1} is not valid"
exit 1
fi
}
# set new cd function as cd alias
alias cd='cd_'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment