Skip to content

Instantly share code, notes, and snippets.

@dkvdm
Created January 4, 2016 08:08
Show Gist options
  • Save dkvdm/985432065cdb83487afa to your computer and use it in GitHub Desktop.
Save dkvdm/985432065cdb83487afa to your computer and use it in GitHub Desktop.
Automatically use pew to enter virtualenv based on path with zsh
# 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