Skip to content

Instantly share code, notes, and snippets.

@darklow
Last active December 13, 2015 21:18
Show Gist options
  • Save darklow/4976031 to your computer and use it in GitHub Desktop.
Save darklow/4976031 to your computer and use it in GitHub Desktop.
Auto-detect virtualenv relatively from current directory
# auto source virtual envs if it can find one
has_virtualenv() {
path="../env/bin/activate"
if [ -e $path ]; then
path=$(readlink -f $path)
if [ -z "$CURRENT_VENV_PATH" -o -z "$_OLD_VIRTUAL_PATH" -o "$CURRENT_VENV_PATH" != "$path" ] ; then
source $path
export CURRENT_VENV_PATH="$path"
echo -e "\e[01;30mvirtualenv $path activated\e[00m"
fi
fi
}
venv_cd () {
cd "$@" && has_virtualenv
}
alias cd="venv_cd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment