Skip to content

Instantly share code, notes, and snippets.

@bboc
Forked from dbtek/venv_wrapper
Last active February 5, 2021 12:40
Show Gist options
  • Save bboc/4021d65bc16af0a9c8d1d541064f0fd6 to your computer and use it in GitHub Desktop.
Save bboc/4021d65bc16af0a9c8d1d541064f0fd6 to your computer and use it in GitHub Desktop.
Python 3 venv wrapper. Manages all virtual environments under ~/.venv/ .
# include following in .bashrc / .bash_profile / .zshrc
# usage
# $ mkvenv myvirtualenv # creates venv under ~/.venv/
# $ venv myvirtualenv # activates venv
# $ deactivate # deactivates venv
# $ rmvenv myvirtualenv # removes venv
#
# From: https://gist.github.com/dbtek/fb2ddccb18f0cf63a654ea2cc94c8f19
export VENV_HOME="$HOME/dev/.venv"
[[ -d $VENV_HOME ]] || mkdir $VENV_HOME
lsvenv() {
ls -1 $VENV_HOME
}
venv() {
if [ $# -eq 0 ]
then
echo "Please provide venv name"
else
source "$VENV_HOME/$1/bin/activate"
fi
}
mkvenv() {
if [ $# -eq 0 ]
then
echo "Please provide venv name"
else
python3 -m venv $VENV_HOME/$1
fi
}
rmvenv() {
if [ $# -eq 0 ]
then
echo "Please provide venv name"
else
rm -r $VENV_HOME/$1
fi
}
complete -W "`lsvenv`" venv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment