Skip to content

Instantly share code, notes, and snippets.

@rthill
Last active June 5, 2018 09:00
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 rthill/6a663577f7fb17e747699dec668d25bc to your computer and use it in GitHub Desktop.
Save rthill/6a663577f7fb17e747699dec668d25bc to your computer and use it in GitHub Desktop.
Python virtualenv wrapper script
Add into your .bashrc on macOS the following alias:
alias workon='source ~/bin/workon.sh'
I believe on Linux the alias should look like:
alias workon='~/bin/workon.sh'
#!/bin/sh
#
# Workon virtualenv wrapper
#
VENVDIR=~/Pyenv
ENV=$1
DIR=`find $VENVDIR -maxdepth 1 -type d -iname $ENV -print -quit`
if [[ ! -z "${DIR}" ]]; then
echo "Activating virtualenv $ENV"
if [[ ! -z "$VIRTUAL_ENV" ]]; then
echo "Deactivating old virtualenv"
deactivate
fi
source $DIR/bin/activate
else
echo "Cannot find virtualenv!"
echo "Valid virtualenvs:"
find $VENVDIR -maxdepth 1 -type d -execdir echo " {}" \;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment