Skip to content

Instantly share code, notes, and snippets.

@meriadec
Created August 22, 2016 11:00
Show Gist options
  • Save meriadec/de283bf70c501e2ea3add734a9d3cf84 to your computer and use it in GitHub Desktop.
Save meriadec/de283bf70c501e2ea3add734a9d3cf84 to your computer and use it in GitHub Desktop.
#!/bin/bash
getCode () {
curl -s -I http://registry.npmjs.org/$1 | grep HTTP | awk {'print $2'}
}
isAvailable () {
res=$(getCode $1)
if [ "$res" == "404" ]; then
echo 1
else
echo 0
fi
}
printf "\n>> Querying npm registry...\n\n"
available=$(isAvailable $1)
if [ "$available" -eq 1 ]; then
printf "Package [\e[0;32m$1\e[0;0m] is available!\n"
else
printf "\e[0;31mPackage [$1] is not available :(\e[0;0m\n"
fi
echo ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment