How to automatically activate virtualenvs when cd'ing into a directory

后端 未结 12 1992
北海茫月
北海茫月 2020-12-24 06:27

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/

12条回答
  •  一整个雨季
    2020-12-24 06:33

    You should try something like autoenv if not direnv.

    The first one is considered to be "lightweight", while the second one "simply, higher quality software", listening respectively to each one's author, talking about the other one's project. Thus, they seem to me fairly good options, to try both!

    Anyway, both have been tested on zsh shells. In particular, autoenv is really simple to use, after installing it:

    $ git clone git://github.com/inishchith/autoenv.git ~/.autoenv
    $ echo 'source ~/.autoenv/activate.sh' >> ~/.bashrc
    

    just "follow the white rabbit " and try for example

    $ mkdir project
    $ echo "echo 'whoa'" > project/.env
    $ cd project
    whoa
    

    "If a directory contains a .env file, it will automatically be executed when you cd into it. When enabled (set AUTOENV_ENABLE_LEAVE to a non-null string), if a directory contains a .env.leave file, it will automatically be executed when you leave it."

    Have a look at https://github.com/inishchith/autoenv for more detailed instructions!...

提交回复
热议问题