Autoenv: Directory-based Environments

Magic per-project shell environments. Very pretentious.

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:

What is it?

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


Install it easily:

Mac OS X Using Homebrew

$ brew install autoenv
$ echo "source $(brew --prefix autoenv)/" >> ~/.bash_profile

Using pip

$ pip install autoenv
$ echo "source `which`" >> ~/.bashrc

Using git

$ git clone git:// ~/.autoenv
$ echo 'source ~/.autoenv/' >> ~/.bashrc

Using AUR

Arch Linux users can install autoenv or autoenv-git with their favorite AUR helper.

You need to source in your bashrc afterwards:

$ echo 'source /usr/share/autoenv/' >> ~/.bashrc


Before sourcing, you can set the following variables:

  • AUTOENV_AUTH_FILE: Authorized env files, defaults to ~/.autoenv_authorized
  • AUTOENV_ENV_FILENAME: Name of the .env file, defaults to .env
  • AUTOENV_LOWER_FIRST: Set this variable to flip the order of .env files executed
  • AUTOENV_ENV_LEAVE_FILENAME: Name of the .env.leave file, defaults to .env.leave
  • AUTOENV_ENABLE_LEAVE: Set this to a non-null string in order to enable source env when leaving
  • AUTOENV_ASSUME_YES: Set this variable to silently authorize the initialization of new environments


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

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).

当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
若有不妥, 欢迎评注提醒:


订阅 substack 体验古早写作:

点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:


关于 ~ DebugUself with DAMA ;-)
公安备案号: 44049002000656 ...::