Skip to content

Instantly share code, notes, and snippets.

@wilfriedE
Last active January 28, 2018 23:45
Show Gist options
  • Save wilfriedE/7a04402fffb28114412b448e554f9a62 to your computer and use it in GitHub Desktop.
Save wilfriedE/7a04402fffb28114412b448e554f9a62 to your computer and use it in GitHub Desktop.
virtualenv help script
function workonit() {
workon $( cat .venvname 2>/dev/null ) " " 2>/dev/null
}
function venvit(){
mkvirtualenv "${PWD##*/}" $*
echo "${PWD##*/}" > .venvname
}
function rmvenv() {
deactivate
rmvirtualenv "$(cat .venvname)"
rm .venvname
}
workonit

Note

Make sure you have virtualenv and virtualenvwrapper setup. Test to make sure workon, mkvirtualenv, rmvirtualenv are valid commands before using this.

Add to .bash_profile

...
source /path_to/workit_scripts.sh
...

Using it

  • Create virtualenv:
    Under project directory, type workonit
    This will create a virtualenv with the name of the project directory and add a .venvname file with the name of the virtualenv

  • Use virutalenv:
    Under project directory, type venvit
    This will use the virtualenv as specified in the .venvname file.
    You can still specify default mkvirtualenv arguments such as -p python3 etc...

  • Delete virutalenv:
    Under project directory, type rmvenv
    This will remove the virtualenv as specified in the .venvname file and remove the file as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment