Last active
August 19, 2020 21:44
-
-
Save brbsix/d0543fb380a991fd2d857270f0a9c31e to your computer and use it in GitHub Desktop.
mktempenv
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
# 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