Last active
June 11, 2020 11:55
-
-
Save jgdev/b69ba2d25e382819920bafdb39ca022b to your computer and use it in GitHub Desktop.
Auto Activate Python VirtualEnv - ZSH
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
# ... your zsh file | |
function _virtualenv_auto_activate() { | |
current_dir=$(pwd) | |
if [[ -d "./venv" && -z "$VIRTUAL_ENV" ]]; then | |
export VIRTUAL_ENV_PATH=$current_dir; | |
source $VIRTUAL_ENV_PATH/venv/bin/activate | |
elif [[ ! -z "$VIRTUAL_ENV" && $current_dir != "$VIRTUAL_ENV_PATH"* ]]; then | |
export VIRTUAL_ENV_PATH=; | |
deactivate | |
fi | |
} | |
chpwd_functions+=(_virtualenv_auto_activate) | |
precmd_functions=(_virtualenv_auto_activate $precmd_functions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment