07 November 2012

A menu shortcut for activating a virtualenv

Here’s a little bash script I wrote for use with virtualenvwrapper that lists your virtualenvs in a menu and let’s you choose one by number:

menuvirtualenv() {
    select env in `lsvirtualenv -b`; do
        if [ -n "$env" ]; then
            workon "$env"
        fi;
        break;
    done;
}
alias v.menu='menuvirtualenv'

Add it to your ~/.profile or ~/.bash_rc or whatever startup file you use in your terminal. I also have it aliased as v.menu to follow the aliasing scheme as shown in my virtualenvwrapper tips post. I like to use this in combination with having set the path for my projects in the .project file of the virtualenv, so from any path I can list off the virtualenvs, type the number of the one I want, and jump right to that project.

Here’s an example use case:

12:54:26 pcoles@peters_air:~ > v.menu 
1) category-cms
2) collect
3) mrcoles
4) readmd
#? 3
(mrcoles)12:54:33 pcoles@peters_air:~/projects/mrcoles >


Related Posts:
Tips for using pip + virtualenv + virtualenvwrapper
mkdjangovirtualenv: an easier way to setup a virtualenv for django projects




Did you find this helpful or fun? paypal.me/mrcoles
comments powered by Disqus

Peter Coles

Peter Coles

is a software engineer living in NYC who is building Superset 💪 and also created GoFullPage 📸
more »

github · soundcloud · @lethys · rss