Skip to content

Instantly share code, notes, and snippets.

@toranb
Created April 13, 2012 00:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toranb/2372372 to your computer and use it in GitHub Desktop.
Save toranb/2372372 to your computer and use it in GitHub Desktop.
Auto workon virtualenv bash script based on current directory name
workon_virtualenv() {
if [ -e .git ]; then
current_dir="${PWD##*/}"
if [ -e ~/virtualenvs/$current_dir ]; then
deactivate >/dev/null 2>&1
source ~/virtualenvs/$current_dir/bin/activate
fi
fi
}
virtualenv_cd() {
cd "$@" && workon_virtualenv
}
alias cd="virtualenv_cd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment