いまさらdirenv使ってみる

動機

install

brew install direnv
==> Downloading https://homebrew.bintray.com/bottles/direnv-2.7.0.yosemite.bottle.tar.gz

direnv
direnv v2.7.0
Usage: direnv COMMAND [...ARGS]

ずらずらー

.zshrc

# direnv
eval "$(direnv hook zsh)"

source ~/.zshrc で反映

試してみた

  • 単純だけど単純じゃない
  • 意図しない変更を許容しないようにしている
# echo "export MY_ENV=ababa" > .envrc
direnv edit .
direnv: loading .envrc
direnv: export +MY_ENV

vim .envrc
export MY_ENV=ababac
direnv: error .envrc is blocked. Run `direnv allow` to approve its content.

direnv allow .
direnv: loading .envrc
direnv: export +MY_ENV

vim .envrc
export MY_ENV=ababa
direnv: loading .envrc
direnv: export +MY_ENV

direnv deny .
vim .envrc
export MY_ENV=ababac
direnv: error .envrc is blocked. Run `direnv allow` to approve its content.

cd ..
direnv: unloading
env | grep MY_ENV | wc -l
       0