@kokiito0926/pseudoalias 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +55 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// いちおう、Bashで入力補完が効くようになった。
|
|
4
|
+
// タブを1回だけ押したときに入力補完が決まるようになった。
|
|
5
|
+
// それから、ファイルのパスの入力補完も効くようになった。
|
|
6
|
+
// >> $ complete -C "pseudoalias --config ./example.js --completion" -o default pseudoalias
|
|
7
|
+
// >> 2026/01/27 21:36.
|
|
8
|
+
|
|
9
|
+
// いちおう、入力補完のコマンドを書いておいたほうがいい。
|
|
10
|
+
// -oのオプションにdefaultを指定していても、ファイルのパスの入力補完が効かない。
|
|
11
|
+
// >> $ complete -p
|
|
12
|
+
// >> $ complete -r pseudoalias
|
|
13
|
+
// >> $ complete -C "./index.js --config ./example.js --completion" -o default pseudoalias
|
|
14
|
+
// >> 2026/01/27 20:53.
|
|
15
|
+
|
|
16
|
+
// 入力補完の単語を表示する機能を実装した。
|
|
17
|
+
// >> $ ./index.js --config ./example.js --completion
|
|
18
|
+
// >> 2026/01/27 20:18.
|
|
19
|
+
|
|
3
20
|
// ホームディレクトリに設定のファイルを保存できるようにする。
|
|
4
21
|
// そのようにすれば、コマンドをより短くすることができると思う。
|
|
5
22
|
// そのような処理を実装するのであれば、os.homedir関数を用いればいいような気がする。
|
|
@@ -9,17 +26,21 @@
|
|
|
9
26
|
// >> $ node ./index.js --config example.js greetings
|
|
10
27
|
// >> $ node ./index.js --config example.js addition 1 2
|
|
11
28
|
|
|
12
|
-
import { minimist, path, argv } from "zx";
|
|
29
|
+
import { minimist, fs, path, argv } from "zx";
|
|
13
30
|
import { pathToFileURL } from "node:url";
|
|
14
31
|
|
|
15
32
|
const commands = argv._;
|
|
16
33
|
|
|
17
34
|
const args = minimist(process.argv.slice(2));
|
|
18
35
|
const config = args.config;
|
|
36
|
+
const completion = args.completion;
|
|
19
37
|
// console.log(argv);
|
|
20
38
|
// console.log(args);
|
|
21
39
|
// process.exit(0);
|
|
22
40
|
|
|
41
|
+
// console.log("aaaa\nbbbb\ncccc");
|
|
42
|
+
// process.exit(0);
|
|
43
|
+
|
|
23
44
|
const targetFile = config;
|
|
24
45
|
if (!targetFile) {
|
|
25
46
|
process.exit(0);
|
|
@@ -40,6 +61,39 @@ try {
|
|
|
40
61
|
// console.log(restArgs);
|
|
41
62
|
// process.exit(0);
|
|
42
63
|
|
|
64
|
+
// const prevWord = process.argv[process?.argv?.length - 1];
|
|
65
|
+
// const currentWord = process.argv[process?.argv?.length - 2];
|
|
66
|
+
|
|
67
|
+
if (completion) {
|
|
68
|
+
// fs.writeFileSync("./temp.txt", prevWord, "utf-8");
|
|
69
|
+
// fs.writeFileSync("./temp.txt", currentWord, "utf-8");
|
|
70
|
+
// process.exit(0);
|
|
71
|
+
|
|
72
|
+
const args2 = process.argv;
|
|
73
|
+
const prevWord = args2[args2.length - 1];
|
|
74
|
+
const currentWord = args2[args2.length - 2];
|
|
75
|
+
|
|
76
|
+
if (prevWord === "pseudoalias") {
|
|
77
|
+
const candidates = Object.keys(aliasModule).filter((k) => k !== "default");
|
|
78
|
+
// const candidates = ["addition", "division", "greetings", "multiplication", "subtraction"];
|
|
79
|
+
|
|
80
|
+
const filtered = candidates.filter((c) => c.startsWith(currentWord));
|
|
81
|
+
|
|
82
|
+
if (filtered.length > 0) {
|
|
83
|
+
console.log(filtered.join("\n"));
|
|
84
|
+
}
|
|
85
|
+
process.exit(0);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// if (prevWord === "pseudoalias") {
|
|
89
|
+
// const availableFunctions = Object.keys(aliasModule).filter((k) => k !== "default");
|
|
90
|
+
// console.log(availableFunctions.join("\n"));
|
|
91
|
+
// process.exit(0);
|
|
92
|
+
// }
|
|
93
|
+
|
|
94
|
+
process.exit(0);
|
|
95
|
+
}
|
|
96
|
+
|
|
43
97
|
if (!subCommand) {
|
|
44
98
|
const availableFunctions = Object.keys(aliasModule).filter((k) => k !== "default");
|
|
45
99
|
console.log("Available aliases:");
|