Created
February 2, 2023 19:54
-
-
Save idrise/66c85776d161d06c10dc8e37681e8e71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sometimes I fish but mostly I zsh