DEV Community

Discussion on: Local Aliases in Bash

kopseng profile image
Carl-Erik Kopseng

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; }
Enter fullscreen mode Exit fullscreen mode

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

echo 'export NPMBIN="$(npm bin)/pnpm"' >> ~/my/dev/folder/.envrc
Enter fullscreen mode Exit fullscreen mode

This will make sure you use pnpm in my/dev/folder and npm everywhere else.