A Universal Terminal alias for bun, pnpm, npm, and yarn
I’ve accidentally typed
npm for the last time.
This is the zsh script I made to detect and run the correct package manager every time:
npm, and even ::shudders::
This function ensures that I don’t irritate myself as I switch between projects — typing
npm start when I meant
bun start or
npm i when I mant
Working in projects with different package managers, I often type the wrong command and then loose time to confusing runtime errors or unwanted lock files.
This function does not create a universal interface around the different package managers.
I rarely have trouble using the right commands in the right project. And I enjoy utilizing the subtlies in each package manager.
Universal interfaces are a great way to unlearn everything that makes anything good.
This function is more akin to an alias that prevents bugs.
Check out the attached references if you want to learn how to set up zsh functions.