forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmask.ts
33 lines (28 loc) · 1.03 KB
/
mask.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
// To learn more about FIg's autocomplete standard visit: https://fig.io/docs/autocomplete/building-a-spec#building-your-first-autocomplete-spec
// var executeShellCommand: Fig.ExecuteShellCommandFunction;
// The below is a dummy example for git. Make sure to change the file name!
export const completion: Fig.Spec = {
name: "mask",
generateSpec: async (context, executeShellCommand) => {
// See if use specified a maskfile location
var maskfileLocationIdx = context.indexOf("--maskfile");
var out;
// mask --maskfile path/tp/thing build
if (maskfileLocationIdx < 0 || maskfileLocationIdx + 3 > context.length) {
out = await executeShellCommand("cat maskfile.md 2> /dev/null");
} else {
out = await executeShellCommand(
`cat ${context[maskfileLocationIdx + 1]} 2> /dev/null`
);
}
if (!out) return { name: "null" };
return {
name: "mask",
subcommands: out.match(/##.*/g).map((elm) => {
return {
name: elm.slice(3),
};
}),
};
},
};