Skip to content

Commit

Permalink
feat(shell): add python virtual environment commands
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia committed Jun 2, 2023
1 parent 2952c10 commit 601fb6f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 25 deletions.
26 changes: 1 addition & 25 deletions chezmoi/dot_config/shrc/00-dotfiles-export.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -330,28 +330,4 @@ DOTFILES_PKGS_TO_INSTALL+=(${DOTFILES_PKGS_USER[@]})
export DOTFILES_PKGS_TO_INSTALL

# Python Virtual Environment
export WORKON_HOME=$HOME/.venvs
function workon {
if [ -z "$1" ]; then
echo "Usage: workon <virtualenv>"
return
fi
if [ -d "$WORKON_HOME/$1" ]; then
source "$WORKON_HOME/$1/bin/activate"
else
echo "No such virtualenv: $1"
fi
}
function mkvirtualenv {
if [ -z "$1" ]; then
echo "Usage: mkvirtualenv <virtualenv>"
return
fi
if [ ! -d "$WORKON_HOME/$1" ]; then
python3 -m venv "$WORKON_HOME/$1"
source "$WORKON_HOME/$1/bin/activate"
pip install --upgrade pip setuptools wheel
else
echo "Already exists: $1"
fi
}
export WORKON_HOME="$HOME/.venvs"
46 changes: 46 additions & 0 deletions chezmoi/dot_config/shrc/30-aliases.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,49 @@ alias tla="task --list-all"
alias gt="gtask"
alias gtls="gtask --list"
alias gtla="gtask --list-all"

# Python Virtual Environment
function workon {
if [ -z "$1" ]; then
echo "Usage: workon <virtualenv>"
return
fi
if [ -d "$WORKON_HOME/$1" ]; then
source "$WORKON_HOME/$1/bin/activate"
else
echo "No such virtualenv: $1"
fi
}
function mkvirtualenv {
if [ -z "$1" ]; then
echo "Usage: mkvirtualenv <virtualenv> [--system-site-packages]"
return
fi

local use_system_site_packages=0

for arg in "$@"; do
case $arg in
--system-site-packages)
use_system_site_packages=1
;;
esac
done

if [ ! -d "$WORKON_HOME/$1" ]; then
if [ $use_system_site_packages -eq 1 ]; then
python3 -m venv "$WORKON_HOME/$1" --system-site-packages
else
python3 -m venv "$WORKON_HOME/$1"
fi
source "$WORKON_HOME/$1/bin/activate"
pip install --upgrade pip setuptools wheel
else
echo "Already exists: $1"
fi
}
alias mkvenv="mkvirtualenv"
alias mkvirtualenv-system="mkvirtualenv --system-site-packages"
alias mkvenvs="mkvirtualenv-system"
alias rmvirtualenv="rm -rf $WORKON_HOME/\$1"
alias rmvenv="rmvirtualenv"

0 comments on commit 601fb6f

Please sign in to comment.