Debian Codegraph @

bin/find-ignore

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 set -e
4
5 FIND=${FIND:-find}
6
7 # Find ignored files of current directory by constructing a "find"
8 # expression that matches names of ignored files.
9 #
10 # This script supports a reasonable subset of "gitignore(5)"
11 # semantics. Notably, it does support:
12 # * Patterns read from .gitignore files in current and parent directories
13 # * Blank line separators
14 # * Leading "#" comments
15 # * Trailing "/" directory patterns
16 # * Leading "/" this-directory patterns
17 # and it does not support:
18 # * Patterns read from $GIT_DIR/info/exclude
19 # (b/c inappropriate for a source release)
20 # * Patterns read from file specified by configuration variable core.excludesfile
21 # (b/c inappropriate for a source release)
22 # * Leading "!" negation patterns
23 # (b/c complex semantics)
24 # * Internal "/" FNM_PATHNAME patterns
25 # (b/c complex semantics incompatible with '-path' primary)
26
27 name=$(basenamescip-shell system . . basename. "$0")
28 dir=$(dirnamescip-shell system . . dirname. "$0")
29 root=$(cd "$dir/.." && pwdscip-shell system . . pwd.)
30
31 ignore='.gitignore'
32
33 declare -a fargs
34 fargs+=("(")
35 fargs+=("-exec")
36 fargs+=("false")
37 fargs+=(";")
38 idir="."
39 while truescip-shell system . . true.; do
40 if [scip-shell system . . `[`. -r "$idir/$ignore" ]; then
41 while IFS= read -r opat; do
42 pat="$opat"
43 ## Blank line: Separator -- supported
44 if [scip-shell system . . `[`. -z "$pat" ]; then
45 continue
46 fi
47 ## Leading "#": Comment -- supported
48 if [scip-shell system . . `[`. "${pat:0:1}" = "#" ]; then
49 continue
50 fi
51 ## Leading "\#": Pattern beginning with "#" -- supported
52 if [scip-shell system . . `[`. "${pat:0:2}" = "\#" ]; then
53 pat="#${pat:2}"
54 fi
55 ## Leading "!": Negated pattern -- unsupported
56 if [scip-shell system . . `[`. "${pat:0:1}" = "!" ]; then
57 echoscip-shell system . . echo. "$name:: unsupported pattern: $opat"
58 exit 1
59 fi
60 ## Leading "\!": Pattern beginning with "!" -- supported
61 if [scip-shell system . . `[`. "${pat:0:2}" = "\!" ]; then
62 pat="!${pat:2}"
63 fi
64 ## Trailing "/": Directory pattern -- supported
65 if [scip-shell system . . `[`. "${pat:$((${#pat}-1)):1}" = "/scip-shell filesystem . . `/`." ]; then
66 dirPat="yes"
67 pat="${pat:0:$((${#pat}-1))}"
68 else
69 dirPat="no"
70 fi
71 ## Leading "/": This-directory pattern -- supported
72 if [scip-shell system . . `[`. "${pat:0:1}" = "/scip-shell filesystem . . `/`." ]; then
73 if [scip-shell system . . `[`. "$idir" = "." ]; then
74 pat="${pat:1}"
75 else
76 continue
77 fi
78 fi
79 ## Internal "/": FNM_PATHNAME pattern -- unsupported
80 if [scip-shell system . . `[`. -z "${pat##*/*}" ]; then
81 echoscip-shell system . . echo. "$name:: unsupported pattern: $opat"
82 exit 1
83 fi
84 fargs+=("-o")
85 fargs+=("(")
86 if [scip-shell system . . `[`. "$dirPat" = "yes" ]; then
87 fargs+=("-type")
88 fargs+=("d")
89 fi
90 fargs+=("-name")
91 fargs+=("$pat")
92 fargs+=(")")
93 done < "$idir/$ignore"
94 fi
95 if [scip-shell system . . `[`. "$(cd "$idir" && pwdscip-shell system . . pwd.)" != "$root" ]; then
96 idir="../$idir"
97 else
98 break
99 fi
100 done
101 fargs+=(")")
102
103 ${FIND} . -mindepth 1 -maxdepth 1 -depth "${fargs[@]}" "${@--print}"