Created
January 4, 2016 08:08
-
-
Save dkvdm/985432065cdb83487afa to your computer and use it in GitHub Desktop.
Automatically use pew to enter virtualenv based on path with 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
# Automatically activate pew virtualenv | |
function pew_venv_hook() { | |
envs=("${(s/ /)$(pew ls)}") | |
new_env="" | |
_venv=$(basename "$VIRTUAL_ENV") | |
current_env=$_venv${_venv:+} | |
for env in $envs; do | |
if [[ "$PWD" =~ $env ]] | |
then | |
new_env=$env | |
fi | |
done | |
if [[ "$new_env" != "" ]] | |
then | |
if [[ "$new_env" != "$current_env" ]] | |
then | |
pew workon $new_env | |
fi | |
else | |
if [[ "" != "$current_env" ]] | |
then | |
exit | |
fi | |
fi | |
} | |
chpwd_functions=(${chpwd_functions[@]} "pew_venv_hook") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment