Magic per-project shell environments
Note: you should probably use direnv instead. Simply put, it is higher quality software. But, autoenv is still great, too. Maybe try both? :)
This image sums up the relationship between the two projects, very well:
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.
This is great for...
- auto-activating virtualenvs
- auto-deactivating virtualenvs
- project-specific environment variables
- making millions
You can also nest envs within each other. How awesome is that!?
When executing, autoenv, will walk up the directories until the mount
point and execute all .env files beginning at the top.
Follow the white rabbit:
$ echo "echo 'whoa'" > project/.env
$ cd project
whoaInstall it easily:
$ brew install autoenv
$ echo "source $(brew --prefix autoenv)/activate.sh" >> ~/.bash_profile$ git clone git://github.com/inishchith/autoenv.git ~/.autoenv
$ echo "source ~/.autoenv/activate.sh" >> ~/.bashrcDownload the @hyperupcall/autoenv package
$ npm install -g '@hyperupcall/autoenv'
$ echo "source \"\$(npm root -g)/@hyperupcall/autoenv/activate.sh\"" >> ~/.bashrcBefore sourcing activate.sh, you can set the following variables:
AUTOENV_AUTH_FILE: Authorized env files, defaults to~/.autoenv_authorizedAUTOENV_ENV_FILENAME: Name of the.envfile, defaults to.envAUTOENV_LOWER_FIRST: Set this variable to a non-null string to flip the order of.envfiles executedAUTOENV_ENV_LEAVE_FILENAME: Name of the.env.leavefile, defaults to.env.leaveAUTOENV_ENABLE_LEAVE: Set this to a non-null string in order to enable source env when leavingAUTOENV_ASSUME_YES: Set this variable to a non-null string to silently authorize the initialization of new environmentsAUTOENV_VIEWER: Program used to display env files prior to authorization. Default:"less -N".
autoenv is tested on:
- bash
- zsh
- dash
- fish is supported by autoenv_fish
- more to come
direnv is an excellent alternative to autoenv, and includes the ability to unset environment variables as well. It also supports the fish terminal.
Autoenv overrides cd. If you already do this, invoke autoenv_init
within your custom cd after sourcing activate.sh.
Autoenv can be disabled via unset cd if you experience I/O issues with
certain file systems, particularly those that are FUSE-based (such as
smbnetfs).
Autoenv was originally created by @kennethreitz. Ownership was then transfered to @inishchith. As of August 22nd, 2021, Edwin Kofler (@hyperupcall) owns and maintains the project