Upgrade yt-dlp from version `stable@2024.05.27` to `stable@2024.07.09`
[sunny256-utils.git] / git-ignore
blob3e274123be9aabb5dc30b60c634d83b7a76d52ef
1 #!/bin/sh
3 #==============================================================================
4 # git-ignore
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 #==============================================================================
13 progname=git-ignore
14 VERSION=0.5.0
16 opt_help=0
17 opt_quiet=0
18 opt_subdirs=0
19 opt_top=0
20 opt_verbose=0
21 while test -n "$1"; do
22 case "$1" in
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 ;;
29 --) shift; break ;;
31 if printf '%s\n' "$1" | grep -q ^-; then
32 echo "$progname: $1: Unknown option" >&2
33 exit 1
34 else
35 break
37 break ;;
38 esac
39 done
40 opt_verbose=$(($opt_verbose - $opt_quiet))
42 if test "$opt_help" = "1"; then
43 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
44 cat <<END
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 [...]]
54 Options:
56 -h, --help
57 Show this help.
58 -q, --quiet
59 Be more quiet. Can be repeated to increase silence.
60 -s, --subdirs
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
65 ignored.
66 -t, --top
67 Update the .gitignore in the top directory of the repository instead
68 of .gitignore in the current directory.
69 -v, --verbose
70 Increase level of verbosity. Can be repeated.
71 --version
72 Print version information.
74 END
75 exit 0
78 if test -z "$1"; then
79 echo $progname: No arguments specified >&2
80 exit 1
83 if test "$opt_top" = "1"; then
84 gitignore="$(git rev-parse --show-toplevel)/.gitignore"
85 else
86 gitignore=.gitignore
89 prslash="/"
90 test "$opt_subdirs" = "1" && prslash=""
92 for f in "$@"; do
93 unset termslash
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
98 echo $prslash$(
99 git rev-parse --show-prefix
100 )$f$termslash >>"$gitignore"
101 else
102 # Use local .gitignore in current directory
103 echo $prslash$f$termslash >>"$gitignore"
105 done
107 sort -u "$gitignore" >"$gitignore.tmp"
108 mv "$gitignore.tmp" "$gitignore"
109 git add "$gitignore"
111 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :