X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=states%2Fzsh%2Ffiles%2Fzshrc;fp=states%2Fzsh%2Ffiles%2Fzshrc;h=57c58ec874b7ef601b65ccb439096c6aa588a872;hb=8028d34696a67c53a9dd3f4bc2441d36c5ae2460;hp=e1659e5e47dd06f43d4ca06cd246952842a17ecb;hpb=39f1e517ede6aff07a4a2015d2483d0046b65a48;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 +}