Skip to content

Instantly share code, notes, and snippets.

@oudam-meas
Last active May 24, 2018 07:16
Show Gist options
  • Save oudam-meas/0ee98175c41eb6138b6b0cb8b659af89 to your computer and use it in GitHub Desktop.
Save oudam-meas/0ee98175c41eb6138b6b0cb8b659af89 to your computer and use it in GitHub Desktop.
direnv setup - alway run from binstub

Using direnv

story

understing what is Spring and Binstub, instead of $bundle exec [rails_commands], it's better to use $./bin/[rails_commands] (rails_commands : rails, rspec, setup, rake, etc )

And it's even better to use direnv, since it will shorhand us to type $./bin/[rails_commands] (any executable file in ./bin), to just $[rails_commands], for example: instead of $./bin/rails s, we can just type $rails s.

installation (Mac)

$ brew install direnv

setup

  • add below line to ~/.bashrc or ~/.zshrc (base on your profile)
eval "$(direnv hook bash)"

usage

  1. create .envrc in the root of your project (example here is based on rails project)
  2. add below line to the file
export PATH=./bin:$PATH

white list the direnv for the current directory (one time only)

  • there's a security notice .envrc is not allowed when ever we cd into the project directory, below command will whitelist the current dir.
$ direnv allow .

action

now when you test, instead of ~/.rbenv/shims/rails, it show ./bin/rails


$ which rails
> ./bin/rails

Enjoy!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment