Skip to content

Instantly share code, notes, and snippets.

@pop
Created March 16, 2018 16:48
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 pop/3b8cb9842e169fb46fb840fb612fa8b0 to your computer and use it in GitHub Desktop.
Save pop/3b8cb9842e169fb46fb840fb612fa8b0 to your computer and use it in GitHub Desktop.
workon
#!/bin/sh
# Put this script in your path.
# Add this line to your .bashrc:
# alias workon='. workon.sh'
PROJECTS_DIR="${PROJECTS_DIR:-$HOME/Source}"
DEPTH="${DEPTH:-6}"
goto_dir () {
d=`find $PROJECTS_DIR -maxdepth $DEPTH -name $1`
if [ ! -z $d ]; then
cd $d
else
return 1
fi
}
checkout_branch () {
git checkout $1
}
if [ "$#" -eq 1 ]; then
goto_dir $1
elif [ "$#" -eq 2 ]; then
goto_dir $1
checkout_branch $2
else
echo 'Usage: workon <project> [branch]'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment