Skip to content

Instantly share code, notes, and snippets.

@rorhug
Last active September 15, 2025 12:32
Show Gist options
  • Select an option

  • Save rorhug/4682e3ce775f9dfe7a9c8867886c2a57 to your computer and use it in GitHub Desktop.

Select an option

Save rorhug/4682e3ce775f9dfe7a9c8867886c2a57 to your computer and use it in GitHub Desktop.
Use the right js package manager
p() {
if [[ -f bun.lockb ]]; then
echo "Using bun"
command bun "$@"
elif [[ -f pnpm-lock.yaml ]]; then
echo "Using pnpm"
command pnpm "$@"
elif [[ -f yarn.lock ]]; then
echo "Using yarn"
command yarn "$@"
elif [[ -f package-lock.json ]]; then
echo "Using npm"
command npm "$@"
elif [[ -f deno.json ]]; then # untested
echo "Using deno"
command deno "$@"
else
if [[ "${ZSH_ALIAS_EXPANSION:-}" == "npm" ]]; then
echo "No js package manager detected, using npm"
command npm "$@"
else
echo "No js package manager detected"
fi
fi
}
alias npm='ZSH_ALIAS_EXPANSION=npm p'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment