Fish shell tooling to automagically activate and deactivate Python's virtualenv when moving between directories.
⚠️ This is a Fish shell script, it will not work on Bash or Zsh.
For example, let's say you have a project in ~/my-project
with a virtualenv inside:
~ $ # note that no virtualenv is active
~ $ cd ~/my-project
(.venv) my-project $ # note that the virtualenv was activated
(.venv) my-project $ cd ~
~ $ # now the virtualenv is deactivated
By default it will look for .venv
or venv
. But you can replace that with DIRVENV_DIRS
environment variable. For example, if you want it to look for virtualenv called forty
or two
:
set -x DIRVENV_DIRS forty,two
If you manually activates a virtualenv, dirvenv
will not deactivate it.
For example, if you have ~/my-project/.venv
and you cd ~/my-project/tests
, it will activate the virtualenv in the parent directory (recursively).
If you have more than one shell, dirvenv
from one shell will not mess up with the magic in the other shells.
If you want dirvenv
to ignore any directory, just use DIRVENV_IGNORE
with full paths to the directories. For example:
set -x DIRVENV_IGNORE /not/my/monkeys,/not/my/circus
From now on, dirvenv
will ignore any action in both these directories and their sub-directories.
Probably it works with Fisher, but I haven't tested it myself:
$ fisher install cuducos/dirvenv.fish
Alternatively you can use the install.fish
script:
$ curl https://raw.githubusercontent.com/cuducos/dirvenv.fish/refs/heads/main/install.fish | source
There is an uninstall.fish
script for that:
$ curl -LO https://raw.githubusercontent.com/cuducos/dirvenv.fish/refs/heads/main/uninstall.fish
$ source uninstall.fish
$ rm uninstall.fish
Thank you, direnv
! The similarity in the name is intentional, the user experience of direnv
is so great I wanted to offer the same seamless smooth experience with dirvenv
: )