Skip to content

Instantly share code, notes, and snippets.

@jakowicz
Created May 24, 2015 12:48
Show Gist options
  • Save jakowicz/3e03e15f698f9e9251cd to your computer and use it in GitHub Desktop.
Save jakowicz/3e03e15f698f9e9251cd to your computer and use it in GitHub Desktop.
cd change-up
#!/bin/bash
function changeDir() {
foo=$(getRandomDir '/*/')
while [ 1 == 1 ]; do
if [ "$foo" != "" ]; then
builtin cd $foo 2> /dev/null
foo=$(getRandomDir '*/')
else
break;
fi
done
echo "I am not some slave, I'll cd to '`pwd`' instead"
}
function getRandomDir() {
echo `/usr/bin/ls -d $1 -1 2> /dev/null | shuf | head -n 1` 2> /dev/null
}
alias cd="changeDir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment