Skip to content

Instantly share code, notes, and snippets.

@cyeong
Created October 8, 2012 04:06
Show Gist options
  • Save cyeong/3850668 to your computer and use it in GitHub Desktop.
Save cyeong/3850668 to your computer and use it in GitHub Desktop.
change cd behavior after activate
One handy hook I use is to overwrite some shell buildins. For example I have a custom cd, you can do so much with totally localized environments.
proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}')
#this function will overwrite the default behavior of cd to go to the root of the venv, to go to HOME use cd ~
#change postdeactivate as well if you use this hook to revert cd back to ~
cd () {
if (( $# == 0 ))
then
builtin cd ~/projects/$proj_name
else
builtin cd "$@"
fi
}
#move into the venv after activated
cd
ctags -f $VIRTUAL_ENV/tags -R $VIRTUAL_ENV/lib/python2.7/site-packages ${PWD} &> /dev/null & disown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment