Skip to content

Instantly share code, notes, and snippets.

@kfish
Created October 1, 2014 01:27
Show Gist options
  • Save kfish/a8bceecacd4cbd41a11e to your computer and use it in GitHub Desktop.
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
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