-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathkill.ts
63 lines (60 loc) · 1.63 KB
/
kill.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
// Compatibility: macOS
function processIcon(path: string): string {
const idx = path.indexOf(".app/");
if (idx === -1) {
return "fig://icon?type=gear";
}
return "fig://" + path.slice(0, idx + 4);
}
const completionSpec: Fig.Spec = {
name: "kill",
description: "Terminate or signal a process",
args: {
name: "pid",
isVariadic: true,
generators: {
script: ["bash", "-c", "ps axo pid,comm | sed 1d"],
postProcess: (result: string) => {
return result.split("\n").map((line) => {
const [pid, path] = line.trim().split(/\s+/);
const name = path.slice(path.lastIndexOf("/") + 1);
return {
name: pid,
description: path,
displayName: `${pid} (${name})`,
icon: processIcon(path),
};
});
},
},
},
options: [
{
name: "-s",
description: "A symbolic signal name specifying the signal to be sent",
args: {
name: "signal_name",
generators: {
// Bash's `kill` builtin has different output to /bin/kill
script: ["env", "kill", "-l"],
postProcess: (out) =>
out.match(/\w+/g)?.map((name) => ({
name,
description: `Send ${name} instead of TERM`,
icon: "fig://icon?type=string",
})),
},
},
},
{
name: "-l",
description:
"If no operand is given, list the signal names; otherwise, write the signal name corresponding to exit_status",
args: {
name: "exit_status",
isOptional: true,
},
},
],
};
export default completionSpec;