Skip to content

Instantly share code, notes, and snippets.

@brbsix
Last active August 19, 2020 21:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brbsix/d0543fb380a991fd2d857270f0a9c31e to your computer and use it in GitHub Desktop.
Save brbsix/d0543fb380a991fd2d857270f0a9c31e to your computer and use it in GitHub Desktop.
mktempenv
# Create a temporary pyenv virtualenv
mktempenv(){
[[ $1 =~ ^(-h|--help)$ ]] && {
echo "Usage: ${FUNCNAME[0]} [VERSION] [NAME]"
echo 'Create a temporary pyenv virtualenv'
return 0
}
local pyenv_version=${1:-$(pyenv version-name)}
local venv_name=${2:-$(mktemp --dry-run -d "tmp-$pyenv_version-XXXXXX")}
pyenv virtualenv "$pyenv_version" "$venv_name" || {
echo 'ERROR: command exited unsuccessfully' >&2
return 1
}
echo
echo "Entering a new shell session with virtualenv '$venv_name' ($pyenv_version)."
echo "It will be removed upon exit (ctrl+d or 'exit')."
PYENV_VERSION=$venv_name "$SHELL"
echo "Destroying temporary virtualenv '$venv_name'."
pyenv uninstall -f "$venv_name"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment