-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathtrap.ts
40 lines (37 loc) · 1011 Bytes
/
trap.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
/*
* Certain shells output signals as "1) SIGHUP 2) SIGINT 3) SIGQUIT" (bash, zsh, ...)
* Other shells output looks like "HUP INT QUIT" (fish, csh, ...)
*/
const re = /(\d+\)\s)?([\w-+]+)/g;
/*
* Generators
*/
const availableSignalsGenerator = (
suggestOptions?: Partial<Fig.Suggestion>
): Fig.Generator => ({
script: "command kill -l",
postProcess: (output) =>
[...output.matchAll(re)].map((signal) => ({
name: signal[2],
})),
});
const completionSpec: Fig.Spec = {
name: "trap",
description:
"Automatically execute commands after receiving signals by processes or the operating system",
options: [
{
name: ["--print", "-p"],
description: "Prints all defined signal handlers",
},
{
name: ["--help", "-h"],
description: "Displays help about using this command",
},
],
args: [
{ name: "function name", isOptional: true },
{ name: "reason", generators: availableSignalsGenerator() },
],
};
export default completionSpec;