Skip to content

Instantly share code, notes, and snippets.

@afontaine
Last active December 19, 2015 10:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save afontaine/5938335 to your computer and use it in GitHub Desktop.
Save afontaine/5938335 to your computer and use it in GitHub Desktop.
Custom git script to create/append .gitignore file with provided arguments from gitignore.io's REST api. Move to anywhere in your PATH. Generate/Append the repo's .gitignore file using the gitignore.io api git-ignore [-l] <types> ... -l If no other option is present, list available templates. If options do exist, output is redirected to stdout. …
#!/bin/sh
USAGE="[-l] <types> ..."
LONG_USAGE="Generate/Append the repo's .gitignore file using the gitignore.io api
-l
If no other option is present, list available templates.
If options do exist, output is redirected to stdout.
`curl -s http://gitignore.io/api/`"
SUBDIRECTORY_OK=
CHECK=
. "$(git --exec-path)/git-sh-setup"
while getopts "l" OPTION; do
case $OPTION in
l)
CHECK="yes"
;;
[?])
usage
;;
esac
done
shift $(($OPTIND-1))
if [ $CHECK ]; then
if [ $@ ]; then
curl -s "http://gitignore.io/api/`printf ',%s' \"$@\" | cut -c 2-`"
else
curl -s "http://gitignore.io/api/list"
fi
exit 0
fi
if [ $# -eq 0 ]; then
usage
fi
require_work_tree_exists
cd_to_toplevel
touch .gitignore
for arg; do
if [ `grep -ic $arg .gitignore` -eq 0 -a $arg != "list" ]; then
LIST="$LIST${LIST:+,}$arg"
fi
done
curl -s "http://gitignore.io/api/$LIST" | tee -a .gitignore
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment