forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathj.ts
54 lines (47 loc) · 1.59 KB
/
j.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
import autojump from "./autojump";
const completionSpec: Fig.Spec = {
name: "j",
...autojump,
args: {
name: "directory",
description: "Directory to jump to",
isVariadic: true,
generators: {
script: 'cat "$HOME"/Library/autojump/autojump.txt',
postProcess: (out, ctx) => {
const lines = out.split("\n").map((line) => {
const [weight, dir] = line.split("\t");
return {
weight: Number(weight),
dir,
};
});
const args = ctx.slice(1, ctx.length - 1);
// directory arg is variadic with each subsequent arg being an
// additional filter. filtered will filter directories by all args.
const filtered = lines.filter(({ dir }) =>
args.every((arg) => dir.includes(arg))
);
return filtered.map(({ weight, dir }) => {
const splitPath = dir.split("/");
const name = splitPath[splitPath.length - 1];
// arg is variadic but we don't want to suggest something
// that's already been entered. This 'if' prevents redundant
// suggestions.
if (!args.includes(name)) {
return {
name,
description: dir,
// Docs state max weight is 100 but this seems
// to work regardless of any amount over that limit.
// Fig should defer assigning priority to autojump.
// 75 added to keep args above options.
priority: 75 + weight,
};
}
});
},
},
},
};
export default completionSpec;