Created
July 13, 2018 01:43
-
-
Save flesch/999f32f1bc866bc4c3d76bf789d84377 to your computer and use it in GitHub Desktop.
Read or create a package.json file
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
# Add this function to .bashrc or .bash_profile | |
# $ pkg | |
# $ pkg dependencies # (to show only the dpendencies) | |
# Requires `jq` | |
pkg() { | |
if [ -f package.json ]; then | |
cat package.json | jq .$1 | |
else | |
read -p "package.json doesn't exist. Create one? [Y/n] " -n 1 -r | |
if [[ $REPLY =~ ^(Y|y| ) ]] || [[ -z $REPLY ]]; then | |
npm init --yes | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment