Grumpy old fart that throws up a little every time he sees someone being passionate about some javascript lib. Tech agnostic. If it bleeds, I can kill -9 it.
Actually, I found your article when searching for "local bash alias", as autoenv and direnv only supports environment variables, but your article actually pointed me to a more flexible general solution than what you posted!
If you change your function to this:
function npm(){ if [[ -z "$NPMBIN" ]]; then $(which npm) $@; else $NPMBIN $@; fi; }
you can for instance use pnpm as your local npm if the NPMBIN variable is set to point to a local install of that. This is so easy to achieve if you install direnv and do
Actually, I found your article when searching for "local bash alias", as autoenv and direnv only supports environment variables, but your article actually pointed me to a more flexible general solution than what you posted!
If you change your function to this:
you can for instance use
pnpm
as your localnpm
if theNPMBIN
variable is set to point to a local install of that. This is so easy to achieve if you installdirenv
and doThis will make sure you use
pnpm
inmy/dev/folder
andnpm
everywhere else.