Skip to content

Instantly share code, notes, and snippets.

@flesch
Created July 13, 2018 01:43
Show Gist options
  • Save flesch/999f32f1bc866bc4c3d76bf789d84377 to your computer and use it in GitHub Desktop.
Save flesch/999f32f1bc866bc4c3d76bf789d84377 to your computer and use it in GitHub Desktop.
Read or create a package.json file
# 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