-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selector.ts
63 lines (49 loc) · 1.4 KB
/
selector.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
import nfzf from "https://esm.sh/node-fzf@0.11.0";
import { globAll, globalTask } from "./task.ts";
import { exit } from "./utils.ts";
import { colorLog, toggle } from "./clikit.ts";
import { FzfOptions } from "./types.ts";
export function selectScript() {
return selectGlobPath(globAll);
}
async function selectGlobPath(scriptList: Array<Record<string, string>>) {
// const scriptGlob = expandGlobSync("**/.boost/*.ts");
if (scriptList.length <= 0) {
console.log("Notting to Tasks...💤");
try {
const _ = await Deno.stat(globalTask);
} catch {
const result = await toggle(
`No global scripts directory. Create directory in ${globalTask} ?`,
);
if (result) {
Deno.mkdir(globalTask);
colorLog("Created✨", "#ffef5c");
}
}
exit();
}
const result = await nfzf(option(scriptList));
const { selected, query } = result;
if (!selected) {
console.log("No matches for:", query);
} else {
return scriptList[selected.index].path;
}
}
const option = (list: Array<Record<string, string>>) => {
const scriptNameList = Object.entries(list)
.map(([_, value]) => (value.name));
const opts: FzfOptions = {
list: scriptNameList,
mode: "fuzzy" || "normal",
prefill: "",
prelinehook: function (index) {
return "";
},
postlinehook: function (index) {
return "";
},
};
return opts;
};