direnv is a shell extension that loads different environment variables
depending on your path.
Instead of putting every environment variable in your "~/.profile", have directory-specific ".envrc" files for your AWSACCESSKEY, LIBRARY_PATH or other environment variables.
It does some of the job of rvm, rbenv or virtualenv but in a language-agnostic way.
$ cd ~/code/my_project $ ls bin/ lib/ Rakefile README.md $ echo $PATH /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin $ direnv edit . # Opens in your `$EDITOR .envrc`. Add: export PATH=$PWD/bin:$PATH $ direnv: loading .envrc direnv export: ~PATH $ echo $PATH /Users/zimbatm/code/my_project/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin $ cd .. direnv: unloading direnv export: ~PATH $ echo $PATH /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
git clone http://github.com/zimbatm/direnv cd direnv make install # or symlink bin/direnv into your $PATH
For Mac users, you can also use
brew install direnv
This is what is going to enable the direnv extension. It's going to allow direnv to execute before every prompt command and adjust the environment.
Add the following line at the end of your "~/.bashrc" file:
eval "$(direnv hook bash)"
Make sure it appears even after rvm, git-prompt and other shell extensions that manipulate your prompt.
Add the following line at the end of you "~/.zshrc" file:
eval "$(direnv hook zsh)"
If you want to place it in another file replace $0 with "zsh" as zsh changes the value dynamically.
Add the following line at the end of your "~/.config/fish/config.fish" file:
eval (direnv hook fish)
direnv edit . to open an ".envrc" in your $EDITOR. This script is going
to be executed once you exit the editor. Every
export is going to be
available in your shell until you
cd .. out of the directory.
To make your life convenient there is a couple of additional commands in the
.envrc execution context that are loaded from the
Bug reports, contributions and forks are welcome.
For bugs, report them on http://github.com/zimbatm/direnv/issues
Or if you have some cool usages of direnv that you want to share, feel free to put them in the wiki https://github.com/zimbatm/direnv/wiki
Thank you for making direnv better
Copyright (C) 2013 Jonas Pfenniger and contributors under the MIT licence.