Automatically add composer 'vendor/bin' to your $PATH upon entering a project's directory.

By Bill Seremetis, 4 November, 2019

By using direnv you can set environmental variables depending on the current directory. This allows us to alter several variables, like the default Drush URI, by adding the following in our .envrc file:

export DRUSH_OPTIONS_URI=http://0.0.0.0:8888

With this, whenever you type drush uli a proper login link will be constructed.

But why stop here? We can use the same trick to make all composer binaries executable without having to type ./vendor/bin/ every time. Just add this to your .envrc file:

export PATH="$PATH:${PWD}/vendor/bin"

From now on you can just type behat instead of the full or relative path to the behat binary. It also works fine on subfolders, as long as there are no new .envrc files.

Enjoy!