Skip to content

Instantly share code, notes, and snippets.

@bskinn
Last active May 9, 2026 01:17
Show Gist options
  • Select an option

  • Save bskinn/79ea4ea9d0788a850aaf6806935e8bd6 to your computer and use it in GitHub Desktop.

Select an option

Save bskinn/79ea4ea9d0788a850aaf6806935e8bd6 to your computer and use it in GitHub Desktop.
Source-able bash function for activating Python venvs
# Search for venvs in pwd with an optional suffix
# and activate the first one found.
#
# $ vact # Activate first found of env, .env, venv, or .venv
# $ vact [SUFFIX] # Activate first found of envSUFFIX, etc.
#
# Add to, e.g., ~/.bash_aliases. This version should
# work in Linux/WSL bash and in Windows Git Bash.
#
vact () {
local VENV_BIN opt
for opt in env .env venv .venv; do
if [[ -f "${opt}${1:-}/bin/activate" ]]; then VENV_BIN="${opt}${1:-}/bin"; break; fi
if [[ -f "${opt}${1:-}/Scripts/activate" ]]; then VENV_BIN="${opt}${1:-}/Scripts"; break; fi
done
if [[ -n "${VENV_BIN:-}" ]]; then
source ${VENV_BIN}/activate
else
echo "No venv found."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment