Skip to content
This repository

Unclutter your .profile

Merge pull request #110 from halkeye/layout_perl

layout_perl support (local::lib)
latest commit 233f96344e
zimbatm authored
Octocat-spinner-32 man Fix typo of "relative" February 19, 2014
Octocat-spinner-32 script Release scripts April 01, 2013
Octocat-spinner-32 test Refactored the whole export and diff mechanism. Fixes #92 regression. January 12, 2014
Octocat-spinner-32 .gitignore move test/allow .gitignore to root .gitignore December 27, 2013
Octocat-spinner-32 .travis.yml travis-ci: test agains go 1.2 and not against gh-pages December 25, 2013
Octocat-spinner-32 CHANGELOG.md Release v2.3.0 February 06, 2014
Octocat-spinner-32 LICENSE Add a LICENSE file to the repo June 16, 2013
Octocat-spinner-32 Makefile Set the executable bit on direnv. January 21, 2014
Octocat-spinner-32 README.md Fix typo March 05, 2014
Octocat-spinner-32 cmd_allow.go Display command arguments in the help April 01, 2013
Octocat-spinner-32 cmd_apply_dump.go Only backup the diff of environments. Fixes #82 January 11, 2014
Octocat-spinner-32 cmd_deny.go Display command arguments in the help April 01, 2013
Octocat-spinner-32 cmd_dotenv.go Only backup the diff of environments. Fixes #82 January 11, 2014
Octocat-spinner-32 cmd_dotenv_test.go Support more of the dotenv syntax format November 20, 2013
Octocat-spinner-32 cmd_dump.go Refactored the whole export and diff mechanism. Fixes #92 regression. January 12, 2014
Octocat-spinner-32 cmd_edit.go Run the EDITOR inside /bin/sh. Fixes #108 March 07, 2014
Octocat-spinner-32 cmd_exec.go doc February 05, 2014
Octocat-spinner-32 cmd_expand_path.go Display command arguments in the help April 01, 2013
Octocat-spinner-32 cmd_export.go export diff from the old env, not the current env February 05, 2014
Octocat-spinner-32 cmd_help.go Add command aliases. `direnv --help` is an alias to `direnv help` December 24, 2013
Octocat-spinner-32 cmd_hook.go Display command arguments in the help April 01, 2013
Octocat-spinner-32 cmd_reload.go Adds a new `direnv reload` command for convenience May 23, 2013
Octocat-spinner-32 cmd_status.go Simplify command dispatch April 01, 2013
Octocat-spinner-32 cmd_stdlib.go layout_perl support (local::lib) April 12, 2014
Octocat-spinner-32 cmd_version.go Move the version information into the direnv executable. April 01, 2013
Octocat-spinner-32 commands.go Introducing the `direnv exec DIR COMMAND ...` command executor. February 05, 2014
Octocat-spinner-32 config.go Refactored the whole export and diff mechanism. Fixes #92 regression. January 12, 2014
Octocat-spinner-32 const.go Refactored the whole export and diff mechanism. Fixes #92 regression. January 12, 2014
Octocat-spinner-32 env.go Refactored the whole export and diff mechanism. Fixes #92 regression. January 12, 2014
Octocat-spinner-32 env_diff.go Refactored the whole export and diff mechanism. Fixes #92 regression. January 12, 2014
Octocat-spinner-32 env_diff_test.go Refactored the whole export and diff mechanism. Fixes #92 regression. January 12, 2014
Octocat-spinner-32 env_test.go Refactored the whole export and diff mechanism. Fixes #92 regression. January 12, 2014
Octocat-spinner-32 log.go Use $DIRENV_LOG_FORMAT to control log formatting, rather than hard-co… February 05, 2014
Octocat-spinner-32 main.go Use terminal colours for direnv output February 01, 2014
Octocat-spinner-32 marshal.go Only backup the diff of environments. Fixes #82 January 11, 2014
Octocat-spinner-32 rc.go If two paths don't have a common ancestors, don't make them relative. February 28, 2014
Octocat-spinner-32 rc_test.go If two paths don't have a common ancestors, don't make them relative. February 28, 2014
Octocat-spinner-32 shell.go initial support for fish July 27, 2013
Octocat-spinner-32 shell_bash.go Fixes parse error on the bash hook when evaluated on a single line. January 20, 2014
Octocat-spinner-32 shell_fish.go Threat fish's PATH export specially July 27, 2013
Octocat-spinner-32 shell_test.go Fixes shell detection in case $0 doesn't contain a path June 20, 2013
Octocat-spinner-32 shell_zsh.go Makes the zsh hook resistant to double-hooking. October 15, 2013
Octocat-spinner-32 version.go Release v2.3.0 February 06, 2014
Octocat-spinner-32 xdg.go Still WIP but approaching a workable state February 07, 2013
README.md

direnv -- Unclutter your .profile

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 AWS_ACCESS_KEY, LIBRARY_PATH or other environment variables.

It does some of the job of rvm, rbenv or virtualenv but in a language-agnostic way.

Example

$ 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

Install

1. Install the code

git clone http://github.com/zimbatm/direnv
cd direnv
make install
# or symlink bin/direnv into your $PATH

Installing from the repository requires the Go language.

For Homebrew users, you can also use brew install direnv

For MacPorts users, install Go with sudo port install go, then install from the repository.

2. Add the hook for your shell

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.

BASH

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.

ZSH

Add the following line at the end of your "~/.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.

FISH

Add the following line at the end of your "~/.config/fish/config.fish" file:

eval (direnv hook fish)

Usage

Use 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 direnv stdlib.

Loading layered .envrc

Lets say you have the following .envrcs

  • /a/.envrc
  • /a/b/.envrc

If you add the following line in /a/b/.envrc, you can load both of the .envrc when you are in /a/b:

source_env ..

Contribute

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

Build Status

COPYRIGHT

Thank you for making direnv better

  • Alan Brenner (aka. alanbbr) for the fish shell support
  • Alexander Kobel for his patches
  • Brian M. Clapper (aka. bmc) for his patch
  • Joshua Peek (aka. josh) for his patch and support
  • Laurie Young (aka. wildfalcon) for fixing my engrish
  • Magnus Holm (aka. judofyr) for his patches and ideas
  • Martin Aumüller (aka. aumuell) for his patches and awesomeness
  • Peter Waller (aka. pwaller) for his patches and insights
  • Sam Stephenson (aka. sstephenson) for his expand_path code that I stole from https://github.com/sstephenson/bats
  • Tim Cuthbertson (aka. gfxmonk) for his contribution over the last months

Copyright (C) 2013 Jonas Pfenniger and contributors under the MIT licence.

Something went wrong with that request. Please try again.