-
-
Save dekimsey/5961242 to your computer and use it in GitHub Desktop.
now with saner listing as well as not requiring git directory to just list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
USAGE="list | list-single | <types> ..." | |
LONG_USAGE="Generate/Append the repo's .gitignore file using the gitignore.io api | |
`curl -s http://gitignore.io/api/`" | |
SUBDIRECTORY_OK= | |
NONGIT_OK=1 | |
OPTIONS_SPEC= | |
. "$(git --exec-path)/git-sh-setup" | |
total=$# | |
if [ $total -eq 0 ]; then | |
usage | |
fi | |
# If we are only asking for list, print it. | |
if [[ $@ == 'list' || $@ == 'list-single' ]]; then | |
list=$(curl -s "http://gitignore.io/api/list" | tr -cd '[:print:]\n\t' | tr ',' '\n' | sort) | |
if [ $@ == 'list' ]; then | |
echo "$list" | column -c $(tput cols) | |
else | |
echo "$list" | |
fi | |
exit 0 | |
fi | |
# To actually save a gitignore, we have to be in a working tree. | |
require_work_tree_exists | |
cd_to_toplevel | |
for item in $@; do | |
# Skip "list" | |
if [ $item == 'list' ]; then | |
continue; | |
fi | |
done | |
LIST=$(printf ',%s' "$@" | cut -c 2-) | |
# tr == prevent shell injection. for safety | |
curl -s "http://gitignore.io/api/$LIST" | tr -cd '[:print:]\n\t' | tee -a .gitignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment