Last active
June 30, 2016 18:53
-
-
Save xtream1101/de110b8ee1c14aee9940637293a75781 to your computer and use it in GitHub Desktop.
Python virtual envs bash commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this to your .bashrc or .bash_profile file to use | |
# | |
# This gives you access to create and switch between different python envs | |
# To create a venv called 'foo' just type: | |
# `pyve foo` | |
# This will create a python 3 venv and activate it as well | |
# If you are in a different venv and want to switch to foo, enter the same thing | |
pyve(){ | |
env_name=$1 | |
activate_file=~/Virtualenvs/py3/$env_name/bin/activate | |
if [[ ! -a $activate_file ]]; then | |
# If a venv does not exist with that name then create it | |
virtualenv -p python3 ~/Virtualenvs/py3/$env_name | |
fi | |
# Switch to a python3 virtual env, deactivate the current one if there is | |
source $activate_file | |
} | |
_pyve(){ | |
# Tab completion for pyve with the available envs that can be activated | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
envs=`ls ~/Virtualenvs/py3/` | |
COMPREPLY=( $(compgen -W "$envs" -- $cur) ) | |
} | |
# Associate the tab completion | |
complete -F _pyve pyve | |
pyve2(){ | |
env_name=$1 | |
activate_file=~/Virtualenvs/py2/$env_name/bin/activate | |
if [[ ! -a $activate_file ]]; then | |
# If a venv does not exist with that name then create it | |
virtualenv -p python2 ~/Virtualenvs/py2/$env_name | |
fi | |
# Switch to a python3 virtual env, deactivate the current one if there is | |
source $activate_file | |
} | |
_pyve2(){ | |
# Tab completion for pyve with the available envs that can be activated | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
envs=`ls ~/Virtualenvs/py2/` | |
COMPREPLY=( $(compgen -W "$envs" -- $cur) ) | |
} | |
# Associate the tab completion | |
complete -F _pyve2 pyve2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment