Created
December 26, 2018 21:49
-
-
Save pbabics/fe36d5f6f8a635190ca42ff42a253242 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function env_activate() { | |
if [ $# -ne 1 ]; then | |
echo "Usage: env_activate <environment name>" >&2 | |
return | |
fi | |
if [ ! -d "${HOME}/.virtualenvs/${1}" ]; then | |
echo "Virtualenvironment '${1}' does not exist" >&2 | |
return | |
fi | |
source "${HOME}/.virtualenvs/${1}/bin/activate" | |
} | |
alias ea="env_activate" | |
_env_activate() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $(compgen -W "$(find ~/.virtualenvs -maxdepth 1 -mindepth 1 -type d | xargs -n1 basename)" -- $cur) ) | |
} | |
complete -F _env_activate env_activate ea | |
function make_virtualenv() { | |
if [ $# -ne 1 ]; then | |
echo "Usage: make_environment <environment name>" >&2 | |
return | |
fi | |
if [ -d "${HOME}/.virtualenvs/${1}" ]; then | |
echo "Virtualenvironment '${1}' already exists" >&2 | |
return | |
fi | |
virtualenv -p "$(which python3.6)" "${HOME}/.virtualenvs/${1}" | |
} | |
alias mkenv="make_virtualenv" | |
_make_virtualenv() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $(compgen -W "$(pwd | awk -F'/' '{print $NF}')" -- $cur) ) | |
} | |
complete -F _make_virtualenv make_virtualenv mkenv | |
function remove_virtualenv() { | |
if [ $# -ne 1 ]; then | |
echo "Usage: remove_environment <environment name>" >&2 | |
return | |
fi | |
if [ ! -d "${HOMEasd}/.virtualenvs/${1}" ]; then | |
echo "Virtualenvironment '${1}' does not exist" >&2 | |
return | |
fi | |
rm -rf "${HOME}/.virtualenvs/${1}" | |
} | |
alias rmenv="remove_virtualenv" | |
_remove_virtualenv() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $(compgen -W "$(find ~/.virtualenvs -maxdepth 1 -mindepth 1 -type d | xargs -n1 basename)" -- $cur) ) | |
} | |
complete -F _remove_virtualenv make_virtualenv rmenv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment