X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=states%2Fzsh%2Ffiles%2Fzshrc;h=57c58ec874b7ef601b65ccb439096c6aa588a872;hb=95263bf9bc976ede0db6c8fd1b3d3ce4c79bcebd;hp=e1659e5e47dd06f43d4ca06cd246952842a17ecb;hpb=504f01ccfd40303697ea3d13a4ca1aaef74552e1;p=max%2Fsaltfiles.git diff --git a/states/zsh/files/zshrc b/states/zsh/files/zshrc index e1659e5..57c58ec 100644 --- a/states/zsh/files/zshrc +++ b/states/zsh/files/zshrc @@ -71,3 +71,31 @@ fi export WORKON_HOME=~/.virtualenvs source /usr/bin/virtualenvwrapper_lazy.sh + +chpwd() { + src_dir="$(readlink -f ~/src/)/" + if [[ $PWD == "$src_dir"* ]]; then + if git status &>/dev/null; then + venv_name=$(basename $(git rev-parse --show-toplevel)) + if [[ -n "$VIRTUAL_ENV" ]]; then + current_venv_name=$(basename "$VIRTUAL_ENV") + if [[ "$current_venv_name" != "$venv_name" ]]; then + deactivate + workon "$venv_name" + fi + else + if workon | grep -q "$venv_name"; then + workon "$venv_name" + fi + fi + else + if [[ -n "$VIRTUAL_ENV" ]]; then + deactivate + fi + fi + else + if [[ -n "$VIRTUAL_ENV" ]]; then + deactivate + fi + fi +}