Skip to content

Instantly share code, notes, and snippets.

@lukemartin
Last active June 5, 2024 10:36
Show Gist options
  • Save lukemartin/5667328c9597f132724a607ec100197c to your computer and use it in GitHub Desktop.
Save lukemartin/5667328c9597f132724a607ec100197c to your computer and use it in GitHub Desktop.
Automatically use the correct package manager
detect_and_run() {
if [ -f "bun.lockb" ]; then
bun "$@"
elif [ -f "pnpm-lock.yaml" ]; then
pnpm "$@"
elif [ -f "yarn.lock" ]; then
yarn "$@"
elif [ -f "package-lock.json" ]; then
npm "$@"
else
echo "No known package manager lockfile found in the current directory."
return 1
fi
}
# Create an alias to use the function
alias n='detect_and_run'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment