Last active
June 27, 2017 13:24
-
-
Save wikrie/191b6b092682c80aaacdc2e345173670 to your computer and use it in GitHub Desktop.
add function to multiple change directory back and or jump back to an existing directory in path name
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
# function to multiple change directory at once or jump back to an existing directory in the path | |
# using: cd.. n or cd.. dir or cd.. *part_of_directory* | |
function mcd() { | |
case $1 in | |
*[!0-9]*) # check if it is a number | |
cd $( pwd | sed -r "s|(.*/$1[^/]*/).*|\1|" ) # loopup for name or part of name of directory | |
;; # if not a number and not an existing directory of path do nothing | |
*) | |
cd $(printf "%0.0s../" $(seq 1 $1)); # change back directory n times | |
;; | |
esac | |
} | |
alias 'cd..'='mcd' # set alias for function so 2 options to run mcd n or cd.. n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment