-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathgrep.ts
344 lines (343 loc) · 13.6 KB
/
grep.ts
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
const completionSpec: Fig.Spec = {
name: "grep",
description:
"Matches patterns in input text. Supports simple patterns and regular expressions",
args: [
{
name: "search pattern",
suggestCurrentToken: true,
},
{
name: "file",
template: "filepaths",
},
],
options: [
{
name: "--help",
description:
"Print a usage message briefly summarizing these command-line options and the bug-reporting address, then exit",
},
{
name: ["-E", "--extended-regexp"],
description:
"Interpret PATTERN as an extended regular expression (-E is specified by POSIX.)",
},
{
name: ["-F", "--fixed-string"],
description:
"Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by POSIX.)",
},
{
name: ["-G", "--basic-regexp"],
description:
"Interpret PATTERN as a basic regular expression (BRE, see below). This is the default",
},
{
name: ["-e", "--regexp"],
description:
"Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a pattern beginning with a hyphen (-). (-e is specified by POSIX.)",
args: {
name: "pattern",
},
},
{
name: ["-i", "--ignore-case", "-y"],
description:
"Ignore case distinctions in both the PATTERN and the input files. (-i is specified by POSIX.)",
},
{
name: ["-v", "--invert-match"],
description:
"Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)",
},
{
name: ["-w", "--word-regexp"],
description:
"Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore",
},
{
name: ["-x", "--line-regexp"],
description:
"Select only those matches that exactly match the whole line. (-x is specified by POSIX.)",
},
{
name: ["-c", "--count"],
description:
"Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option, count non-matching lines. (-c is specified by POSIX.)",
},
{
name: "--color",
description:
"Surround the matched (non-empty) strings, matching lines, context lines, file names, line numbers, byte offsets, and separators (for fields and groups of context lines) with escape sequences to display them in color on the terminal. The colors are defined by the environment variable GREP_COLORS. The deprecated environment variable GREP_COLOR is still supported, but its setting does not have priority",
args: {
name: "WHEN",
default: "auto",
suggestions: ["never", "always", "auto"],
},
},
{
name: ["-L", "--files-without-match"],
exclusiveOn: ["-l", "--files-with-matches"],
description:
"Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match",
},
{
name: ["-l", "--files-with-matches"],
exclusiveOn: ["-L", "--files-without-match"],
description:
"Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)",
},
{
name: ["-m", "--max-count"],
description:
"Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, grep ensures that the standard input is positioned to just after the last matching line before exiting, regardless of the presence of trailing context lines. This enables a calling process to resume a search. When grep stops after NUM matching lines, it outputs any trailing context lines. When the -c or --count option is also used, grep does not output a count greater than NUM. When the -v or --invert-match option is also used, grep stops after outputting NUM non-matching lines",
args: {
name: "NUM",
},
},
{
name: ["-o", "--only-matching"],
description:
"Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line",
},
{
name: ["-q", "--quiet", "--silent"],
description:
"Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. Also see the -s or --no-messages option. (-q is specified by POSIX.)",
},
{
name: ["-s", "--no-messages"],
description:
"Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU grep, 7th Edition Unix grep did not conform to POSIX, because it lacked -q and its -s option behaved like GNU grep's -q option. USG -style grep also lacked -q but its -s option behaved like GNU grep. Portable shell scripts should avoid both -q and -s and should redirect standard and error output to /dev/null instead. (-s is specified by POSIX.)",
},
{
name: ["-b", "--byte-offset"],
description:
"Print the 0-based byte offset within the input file before each line of output. If -o (--only-matching) is specified, print the offset of the matching part itself",
},
{
name: ["-H", "--with-filename"],
description:
"Print the file name for each match. This is the default when there is more than one file to search",
},
{
name: ["-h", "--no-filename"],
description:
"Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search",
},
{
name: "--label",
description:
"Display input actually coming from standard input as input coming from file LABEL. This is especially useful when implementing tools like zgrep, e.g., gzip -cd foo.gz | grep --label=foo -H something",
args: {
name: "LABEL",
},
},
{
name: ["-n", "--line-number"],
description:
"Prefix each line of output with the 1-based line number within its input file. (-n is specified by POSIX.)",
},
{
name: ["-T", "--initial-tab"],
description:
"Make sure that the first character of actual line content lies on a tab stop, so that the alignment of tabs looks normal. This is useful with options that prefix their output to the actual content: -H,-n, and -b. In order to improve the probability that lines from a single file will all start at the same column, this also causes the line number and byte offset (if present) to be printed in a minimum size field width",
},
{
name: ["-u", "--unix-byte-offsets"],
description:
"Report Unix-style byte offsets. This switch causes grep to report byte offsets as if the file were a Unix-style text file, i.e., with CR characters stripped off. This will produce results identical to running grep on a Unix machine. This option has no effect unless -b option is also used; it has no effect on platforms other than MS-DOS and MS -Windows",
},
{
name: "--null",
description:
"Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name. For example, grep -lZ outputs a zero byte after each file name instead of the usual newline. This option makes the output unambiguous, even in the presence of file names containing unusual characters like newlines. This option can be used with commands like find -print0, perl -0, sort -z, and xargs -0 to process arbitrary file names, even those that contain newline characters",
},
{
name: ["-A", "--after-context"],
description: "Print num lines of trailing context after each match",
args: {
name: "NUM",
},
},
{
name: ["-B", "--before-context"],
description:
"Print num lines of leading context before each match. See also the -A and -C options",
args: {
name: "NUM",
},
},
{
name: ["-C", "--context"],
description:
"Print NUM lines of output context. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given",
args: {
name: "NUM",
},
},
{
name: ["-a", "--text"],
description:
"Treat all files as ASCII text. Normally grep will simply print ``Binary file ... matches'' if files contain binary characters. Use of this option forces grep to output lines matching the specified pattern",
},
{
name: "--binary-files",
description: "Controls searching and printing of binary files",
args: {
name: "value",
default: "binary",
suggestions: [
{
name: "binary",
description: "Search binary files but do not print them",
},
{
name: "without-match",
description: "Do not search binary files",
},
{
name: "text",
description: "Treat all files as text",
},
],
},
},
{
name: ["-D", "--devices"],
description: "Specify the demanded action for devices, FIFOs and sockets",
args: {
name: "action",
default: "read",
suggestions: [
{
name: "read",
description: "Read as if they were normal files",
},
{
name: "skip",
description: "Devices will be silently skipped",
},
],
},
},
{
name: ["-d", "--directories"],
description: "Specify the demanded action for directories",
args: {
name: "action",
default: "read",
suggestions: [
{
name: "read",
description:
"Directories are read in the same manner as normal files",
},
{
name: "skip",
description: "Silently ignore the directories",
},
{
name: "recurse",
description: "Read directories recursively",
},
],
},
},
{
name: "--exclude",
description:
"Note that --exclude patterns take priority over --include patterns, and if no --include pattern is specified, all files are searched that are not excluded. Patterns are matched to the full path specified, not only to the filename component",
args: {
name: "GLOB",
isOptional: true,
},
},
{
name: "--exclude-dir",
description:
"If -R is specified, only directories matching the given filename pattern are searched. Note that --exclude-dir patterns take priority over --include-dir patterns",
isRepeatable: true,
args: {
name: "dir",
template: "folders",
isOptional: true,
},
},
{
name: "-I",
description:
"Ignore binary files. This option is equivalent to --binary-file=without-match option",
},
{
name: "--include",
description:
"If specified, only files matching the given filename pattern are searched. Note that --exclude patterns take priority over --include patterns. Patterns are matched to the full path specified, not only to the filename component",
args: {
name: "GLOB",
isOptional: true,
},
},
{
name: "--include-dir",
description:
"If -R is specified, only directories matching the given filename pattern are searched. Note that --exclude-dir patterns take priority over --include-dir patterns",
args: {
name: "dir",
template: "folders",
isOptional: true,
},
},
{
name: ["-R", "-r", "--recursive"],
description: "Recursively search subdirectories listed",
},
{
name: "--line-buffered",
description:
"Force output to be line buffered. By default, output is line buffered when standard output is a terminal and block buffered otherwise",
},
{
name: ["-U", "--binary"],
description: "Search binary files, but do not attempt to print them",
},
{
name: ["-J", "-bz2decompress"],
description:
"Decompress the bzip2(1) compressed file before looking for the text",
},
{
name: ["-V", "--version"],
description: "Print version number of grep to the standard output stream",
},
{
name: ["-P", "--perl-regexp"],
description: "Interpret pattern as a Perl regular expression",
},
{
name: ["-f", "--file"],
description:
"Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing. (-f is specified by POSIX.)",
args: {
name: "FILE",
template: "filepaths",
},
},
],
additionalSuggestions: [
{
name: "-RIn",
description:
"Search for a pattern [R]ecursively in the current directory, showing matching line [n]umbers, [I]gnoring non-text files",
insertValue: "-RI{cursor}",
},
{
name: "-Hn",
description:
"Print file name with the corresponding line number (n) for each match",
insertValue: "-H{cursor}",
},
],
};
export default completionSpec;