X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=states%2Fzsh%2Ffiles%2Fzshrc;h=57c58ec874b7ef601b65ccb439096c6aa588a872;hb=95263bf9bc976ede0db6c8fd1b3d3ce4c79bcebd;hp=f02b7e36e59b5ccb84bd3769ec8ee20dac2d75da;hpb=675a42561b814004255e1198f3f82783237eb4d8;p=max%2Fsaltfiles.git diff --git a/states/zsh/files/zshrc b/states/zsh/files/zshrc index f02b7e3..57c58ec 100644 --- a/states/zsh/files/zshrc +++ b/states/zsh/files/zshrc @@ -68,3 +68,34 @@ bindkey '^R' history-incremental-search-backward if [[ -f ~/.shell_aliases ]]; then source ~/.shell_aliases 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 +}