Skip to content

Instantly share code, notes, and snippets.

@RWJMurphy
Created February 4, 2013 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RWJMurphy/4704605 to your computer and use it in GitHub Desktop.
Save RWJMurphy/4704605 to your computer and use it in GitHub Desktop.
magic cd
function mcd() {
cd=$(echo $1 | sed 's/\(.\)/\/\1*/g')/
dirs=`\ls -1d $cd 2>/dev/null`
dira=($dirs)
dircount=${#dira[*]}
if [[ $dircount == 0 ]]; then
echo "No match for ${cd}"
elif [[ $dircount == 1 ]]; then
echo cd ${dirs}
cd "${dirs}"
else
if [ -z "$2" ]; then
i=0
for dir in $dirs; do
echo $i $dir
let "i += 1"
done;
else
echo cd ${dira[$2]}
cd "${dira[$2]}"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment