I have a bunch of projects in my ~/Documents
. I work almost exclusively in python, so these are basically all python projects. Each one, e.g. ~/Documents/
Rather than writing a custom script you could use direnv. It's not a zsh specific solution (for that you could try zsh-autoenv), but is well-maintained and easy to use with zsh. Once you've installed it, you'd want to put eval "$(direnv hook zsh)"
at the end of your .zshrc
. At that point you can do:
$ source ~/.zshrc
$ cd foo
$ echo "layout python" > .envrc
direnv: error .envrc is blocked. Run `direnv allow` to approve its content.
$ direnv allow
direnv: loading .envrc
direnv: export +VIRTUAL_ENV ~PATH
Now you should be in your virtualenv. You can test by running pip freeze
to see that your virtualenv specific packages are installed. To deactivate
$ cd ..
direnv: unloading