3 #==============================================================================
5 # File ID: e95d1ab0-30ff-11e4-a73e-fefdb24f8e10
7 # Add entries to .gitignore and delete files from Git.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
21 while test -n "$1"; do
23 -h|
--help) opt_help
=1; shift ;;
24 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
25 -s|
--subdirs) opt_subdirs
=1; shift ;;
26 -t|
--top) opt_top
=1; shift ;;
27 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
28 --version) echo $progname $VERSION; exit 0 ;;
31 if printf '%s\n' "$1" |
grep -q ^
-; then
32 echo "$progname: $1: Unknown option" >&2
40 opt_verbose
=$
(($opt_verbose - $opt_quiet))
42 if test "$opt_help" = "1"; then
43 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
46 Add entries to .gitignore . Default action is to add to .gitignore in
47 the local directory, this can be overriden with -t/--top to update the
48 .gitignore in the top directory of the repository. Wildcards can be
49 used, and if any of the arguments is a directory, a trailing slash will
50 be added if it doesn't exist already.
52 Usage: $progname [options] file [files [...]]
59 Be more quiet. Can be repeated to increase silence.
61 Don't prefix the new entries in .gitignore with '/', let the ignore
62 rule work in all subdirectories too. For example, *.o files should
63 generally be ignored all over the place, but without this option
64 only *.o files in the directory where .gitignore is located are
67 Update the .gitignore in the top directory of the repository instead
68 of .gitignore in the current directory.
70 Increase level of verbosity. Can be repeated.
72 Print version information.
79 echo $progname: No arguments specified
>&2
83 if test "$opt_top" = "1"; then
84 gitignore
="$(git rev-parse --show-toplevel)/.gitignore"
90 test "$opt_subdirs" = "1" && prslash
=""
94 test -d "$f" && { echo "$f" |
grep -q '/$' || termslash
=/; }
95 git ls-files
-- "$f" |
grep -q .
&& git
rm -r --cached "$f"
96 if test "$opt_top" = "1"; then
97 # Use global .gitignore at top of repo
99 git rev-parse
--show-prefix
100 )$f$termslash >>"$gitignore"
102 # Use local .gitignore in current directory
103 echo $prslash$f$termslash >>"$gitignore"
107 sort -u "$gitignore" >"$gitignore.tmp"
108 mv "$gitignore.tmp" "$gitignore"
111 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :