Skip to content

Instantly share code, notes, and snippets.

@rogfrich
Created January 17, 2021 22:07
Show Gist options
  • Save rogfrich/a3941f49c3a6aab6a76d3c9279da7166 to your computer and use it in GitHub Desktop.
Save rogfrich/a3941f49c3a6aab6a76d3c9279da7166 to your computer and use it in GitHub Desktop.
Sample zsh / Bash script with aliases and a function to manage Python venvs
# This script is an example of how to simplify the creation, activation and deactivation of Python virtual environments.
alias we="which python"
alias ae='deactivate &> /dev/null; source ./venv/bin/activate'
alias de="deactivate"
# Function to create an environment and optionally set a custom prompt
ce() {
if [ -z "$1" ] # If the first parameter is an empty string (i.e no parameter supplied)
then
python3 -m venv venv
else
python3 -m venv venv --prompt $1
fi
ae
echo "Created and activated:" && we
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment