Last active
May 9, 2026 01:17
-
-
Save bskinn/79ea4ea9d0788a850aaf6806935e8bd6 to your computer and use it in GitHub Desktop.
Source-able bash function for activating Python venvs
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
| # 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