Skip to content
Browse files

git-ignore template support. Templates are based in https://github.co…

…m/github/gitignore

Signed-off-by: Tj Holowaychuk <tj@vision-media.ca>
  • Loading branch information...
1 parent 38d8a22 commit a5392d54c3805705b42dacba03010a21147010c2 @jweslley jweslley committed with tj
Showing with 26 additions and 1 deletion.
  1. +3 −0 .gitmodules
  2. +3 −0 Readme.md
  3. +19 −1 bin/git-ignore
  4. +1 −0 etc/gitignore
View
3 .gitmodules
@@ -0,0 +1,3 @@
+[submodule "etc/gitignore"]
+ path = etc/gitignore
+ url = git://github.com/github/gitignore.git
View
3 Readme.md
@@ -221,6 +221,9 @@ of commits included in the commitish:
*.o
*.log
+ Adding patterns from an existing template:
+ $ git ignore -t rails
+
## git-delete-branch &lt;name&gt;
Deletes local and remote branch _name_.
View
20 bin/git-ignore
@@ -1,7 +1,25 @@
#!/bin/sh
+template=""
+while getopts "t:" opt; do
+ case "$opt" in
+ t) template=$OPTARG;shift;shift;;
+ esac
+done
+
+if [ ! -z "$template" ]; then
+ gitignoredir="`dirname $0`/../etc/gitignore"
+ selected_template=$(find $gitignoredir -type f -name *.gitignore | xargs -i basename {} .gitignore | grep -i $template)
+ count=$(echo $selected_template | wc -w)
+ case "$count" in
+ 0) echo "The pattern '$template' does not match any available templates." && exit 1;;
+ 1) find $gitignoredir -name $selected_template.gitignore -exec cat {} \; >> .gitignore && echo "... added patterns from template '$selected_template'";;
+ *) echo "Be more specific. $count macthes found:\n$selected_template" && exit 2;;
+ esac
+fi
+
if test $# -eq 0; then
- test -f .gitignore && cat .gitignore
+ test -z $template && test -f .gitignore && cat .gitignore
else
for pattern in $@; do
echo $pattern >> .gitignore
1 etc/gitignore
@@ -0,0 +1 @@
+Subproject commit 0a41318dba7094f7f97646280a0096e30b6cd596

0 comments on commit a5392d5

Please sign in to comment.
Something went wrong with that request. Please try again.