Skip to content

Instantly share code, notes, and snippets.

@CatmanIX
Forked from afontaine/git-ignore
Created July 10, 2013 21:22
Show Gist options
  • Save CatmanIX/5970451 to your computer and use it in GitHub Desktop.
Save CatmanIX/5970451 to your computer and use it in GitHub Desktop.
#!/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