Skip to content

Instantly share code, notes, and snippets.

@idrise
Created February 2, 2023 19:54
Show Gist options
  • Save idrise/66c85776d161d06c10dc8e37681e8e71 to your computer and use it in GitHub Desktop.
Save idrise/66c85776d161d06c10dc8e37681e8e71 to your computer and use it in GitHub Desktop.
function check_package_manager() {
current_dir=$(pwd)
while [ "$(pwd)" != "/" ]; do
if [ -f "pnpm-lock.yaml" ]; then
if [ "${1}" != "pnpm" ]; then
echo "Looks like you're using the wrong package manager, partner!"
echo "It's pnpm time, cowboy."
cd "${current_dir}"
return 1
fi
break
elif [ -f "yarn.lock" ]; then
if [ "${1}" != "yarn" ]; then
echo "Uh oh, it looks like you're using the wrong package manager!"
echo "Time to lasso that dependency with Yarn."
cd "${current_dir}"
return 1
fi
break
elif [ -f "package-lock.json" ]; then
if [ "${1}" != "npm" ]; then
echo "Whoa there, it looks like you're using the wrong package manager!"
echo "Time to wrangle those dependencies with npm."
cd "${current_dir}"
return 1
fi
break
fi
cd ..
done
cd "${current_dir}"
}
alias npm="check_package_manager npm && npm"
alias yarn="check_package_manager yarn && yarn"
alias pnpm="check_package_manager pnpm && pnpm"
@idrise
Copy link
Author

idrise commented Feb 3, 2023

sometimes I fish but mostly I zsh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment