Created
October 1, 2014 01:27
-
-
Save kfish/a8bceecacd4cbd41a11e to your computer and use it in GitHub Desktop.
cdu, cdd: cd up/down lots of empty directories, useful for navigating Java, Scala etc. code trees
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 cd_down_rec () { | |
case $(find ./* -maxdepth 0 -type d -not -name ".*" | wc -l) in | |
1) | |
cd * | |
cd_down_rec | |
;; | |
*) | |
;; | |
esac | |
} | |
function cd_up_rec () { | |
cd .. | |
case $(find ./* -maxdepth 0 -type d -not -name ".*" | wc -l) in | |
1) | |
cd_up_rec | |
;; | |
*) | |
;; | |
esac | |
} | |
dotdot () { | |
l=$1 | |
if [[ $l -gt 0 ]] ; then | |
echo -n "../"; dotdot $(expr $l - 1) | |
fi | |
} | |
function cdd () { | |
path=$1 | |
if [[ $path != "" && -e $path ]]; then | |
cd $path | |
fi | |
cd_down_rec | |
} | |
function cdu () { | |
levels=$1 | |
case $levels in | |
"") | |
cd_up_rec | |
;; | |
*) | |
path=$(dotdot $levels) | |
cd $path | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment