Skip to content

Instantly share code, notes, and snippets.

@martinheidegger
Last active August 29, 2015 14:06
Show Gist options
  • Save martinheidegger/5217df563c8e1edcacbd to your computer and use it in GitHub Desktop.
Save martinheidegger/5217df563c8e1edcacbd to your computer and use it in GitHub Desktop.
Shell script to install a package locally and automatically put a require statement in the clipboard. (mac) "$ curl -sL http://git.io/MPadbw >> ~/.zshrc"
#
# npm-i (https://gist.github.com/martinheidegger/5217df563c8e1edcacbd)
# Helper to make installing a package in node-js more comfortable.
#
npm-i() {
if [[ -z "$1" ]]; then
echo "Usage: npm-i <package> (var)"
else
npm install $1 --save
if [[ "$2" == "var" ]]; then
stmt="var $1 = require(\"$1\");"
else
stmt="require(\"$1\");"
fi
echo "Adding '$stmt' to clipboard."
echo "$stmt" | pbcopy
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment