Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Git script for creating and modifying .gitignore files

View git-ignore
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#!/bin/bash
 
## REPO -- https://github.com/github/gitignore
## DOWNLOADS
DL_IGNORE_URL="https://raw.github.com/github/gitignore/master/"
IGNORE_TREE_URL="https://api.github.com/repos/github/gitignore/git/trees/master"
 
CACHE_IGNORE_LIST="$HOME/.cache/gitignore_list"
CACHE_IGNORE_NAMES="$HOME/.cache/gitignore_list_names"
 
function init_cache() {
if [ ! -d $HOME/.cache ] ; then
mkdir -p $HOME/.cache 2> /dev/null
fi
 
if [ ! -f $CACHE_IGNORE_LIST ] ; then
curl -o $CACHE_IGNORE_LIST -qs $IGNORE_TREE_URL
fi
}
 
function get_ignore_names() {
grep -E 'path":.*\.gitignore' $CACHE_IGNORE_LIST \
| sed 's/.* "\([^"]*\).gitignore",/\1/' \
> $CACHE_IGNORE_NAMES
}
 
function list_ignore_names() {
if [ ! -f $CACHE_IGNORE_NAMES -o $CACHE_IGNORE_NAMES -ot $CACHE_IGNORE_LIST ] ; then
get_ignore_names
fi
cat $CACHE_IGNORE_NAMES
}
 
function display_default_gitignore() {
cat <<-EOM | sed 's/^ *//'
*~
*.lock
.*.swp
*.log
tmp/
db/*
*.DS_Store
*#
.svn
.pyc
EOM
}
 
function get_ignore_file() {
curl -qs "${DL_IGNORE_URL}/${1}.gitignore"
}
 
function show_gitignore() {
if [ "$1" = "" ] ; then
display_default_gitignore
else
match=$(grep -i "$1" "$CACHE_IGNORE_NAMES")
r=$?
if [ "$r" = 0 ] ; then
get_ignore_file "$match"
else
echo "Could not find that name. See the list command"
fi
fi
}
 
function add_ignores() {
for i in "$@"
do
echo $i | tee -a ".gitignore"
done
}
 
#### Execution Starts Here
 
if [ ! "$1" = "init" -a ! "$1" = "list" -a ! "$1" = "add" ] ; then
echo "usage: git ignore <init [TYPE]|list|add <pattern> [pattern2] [...]>"
exit 1
fi
 
init_cache
 
case $1 in
"init")
show_gitignore "$2"
;;
"list")
list_ignore_names
;;
"add")
if [ "$2" = "" ] ; then
echo "Must give at least one pattern to ignore"
exit 1
fi
shift
add_ignores "$@"
;;
*)
echo "Unknown command $1"
;;
esac

echo -e '~\n.DS_Store\n.svn\.o*.so*.pyc' > .gitignore

That's an amazing list. I'd forgotten how many languages there were since I only use a few now.

Owner

This may not be appropriate for directly including in the gitignore repo but I thought it may be interesting for people (@Aqua-Ye, @xpaulbettsx) interested in the @github ignore templates...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.