Last active
January 7, 2020 09:56
-
-
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
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
# 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