@kokiito0926/pseudoalias 0.0.3 → 0.0.5

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.
Files changed (3) hide show
  1. package/README.md +13 -0
  2. package/index.js +48 -25
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -18,6 +18,19 @@ $ pseudoalias --config ./example.js addition 1 2
18
18
  $ pseudoalias --config ./example.js subtraction 2 1
19
19
  ```
20
20
 
21
+ ```bash
22
+ $ pseudoalias --config ./example.js --register
23
+ $ pseudoalias --unregister
24
+
25
+ $ pseudoalias greetings
26
+ $ pseudoalias addition 1 2
27
+ $ pseudoalias subtraction 2 1
28
+ ```
29
+
30
+ ```bash
31
+ $ complete -C "pseudoalias --config ./example.js --completion" -o default pseudoalias
32
+ ```
33
+
21
34
  ## ライセンス
22
35
 
23
36
  [MIT](LICENSE)
package/index.js CHANGED
@@ -22,14 +22,24 @@
22
22
  // そのような処理を実装するのであれば、os.homedir関数を用いればいいような気がする。
23
23
  // >> 2026/01/27 18:33.
24
24
 
25
- // >> $ node ./index.js --config example.js
26
- // >> $ node ./index.js --config example.js greetings
27
- // >> $ node ./index.js --config example.js addition 1 2
25
+ // >> $ ./index.js --config example.js
26
+ // >> $ ./index.js --config example.js greetings
27
+ // >> $ ./index.js --config example.js addition 1 2
28
28
 
29
+ // >> $ ./index.js --config ./example.js --register
30
+ // >> $ ./index.js greetings
31
+ // >> $ ./index.js addition 1 2
32
+ // >> $ ./index.js --unregister
33
+
34
+ import os from "node:os";
29
35
  import { minimist, fs, path, argv } from "zx";
30
36
  import { pathToFileURL } from "node:url";
31
37
 
38
+ const CONFIG_DIR = path.join(os.homedir(), ".pseudoalias");
39
+ const CONFIG_FILE = path.join(CONFIG_DIR, "config.js");
40
+
32
41
  const commands = argv._;
42
+ // console.log(commands);
33
43
 
34
44
  const args = minimist(process.argv.slice(2));
35
45
  const config = args.config;
@@ -38,15 +48,45 @@ const completion = args.completion;
38
48
  // console.log(args);
39
49
  // process.exit(0);
40
50
 
41
- // console.log("aaaa\nbbbb\ncccc");
42
- // process.exit(0);
51
+ if (args.register) {
52
+ if (args.config) {
53
+ const absConfigPath = path.resolve(args.config);
54
+ const configData = fs.readFileSync(absConfigPath, "utf-8");
43
55
 
44
- const targetFile = config;
45
- if (!targetFile) {
56
+ await fs.ensureDir(CONFIG_DIR);
57
+
58
+ await fs.writeFile(CONFIG_FILE, configData, "utf-8");
59
+
60
+ console.log(`Success: Registered config path to ${absConfigPath}`);
61
+ console.log(`Stored in: ${CONFIG_FILE}`);
62
+ } else {
63
+ console.error("Error: --config is required with --register");
64
+ }
65
+ process.exit(0);
66
+ }
67
+
68
+ if (args.unregister) {
69
+ if (await fs.exists(CONFIG_DIR)) {
70
+ await fs.remove(CONFIG_DIR);
71
+ console.log("Success: Unregistered and removed configuration.");
72
+ } else {
73
+ console.log("Notice: No configuration found to unregister.");
74
+ }
46
75
  process.exit(0);
47
76
  }
48
77
 
49
- // const targetPath = targetFile;
78
+ let targetFile = config;
79
+
80
+ if (!targetFile) {
81
+ if (fs.existsSync(CONFIG_FILE)) {
82
+ targetFile = CONFIG_FILE;
83
+ } else {
84
+ process.exit(1);
85
+ }
86
+ }
87
+ // console.log(targetFile);
88
+ // process.exit(0);
89
+
50
90
  const targetPath = path.resolve(targetFile);
51
91
  if (!targetPath) {
52
92
  process.exit(0);
@@ -61,36 +101,19 @@ try {
61
101
  // console.log(restArgs);
62
102
  // process.exit(0);
63
103
 
64
- // const prevWord = process.argv[process?.argv?.length - 1];
65
- // const currentWord = process.argv[process?.argv?.length - 2];
66
-
67
104
  if (completion) {
68
- // fs.writeFileSync("./temp.txt", prevWord, "utf-8");
69
- // fs.writeFileSync("./temp.txt", currentWord, "utf-8");
70
- // process.exit(0);
71
-
72
105
  const args2 = process.argv;
73
106
  const prevWord = args2[args2.length - 1];
74
107
  const currentWord = args2[args2.length - 2];
75
108
 
76
109
  if (prevWord === "pseudoalias") {
77
110
  const candidates = Object.keys(aliasModule).filter((k) => k !== "default");
78
- // const candidates = ["addition", "division", "greetings", "multiplication", "subtraction"];
79
-
80
111
  const filtered = candidates.filter((c) => c.startsWith(currentWord));
81
-
82
112
  if (filtered.length > 0) {
83
113
  console.log(filtered.join("\n"));
84
114
  }
85
115
  process.exit(0);
86
116
  }
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
117
  process.exit(0);
95
118
  }
96
119
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokiito0926/pseudoalias",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "description": "スードーエイリアス(pseudoalias)を用いれば、擬似的なエイリアスを作成することができます。",
6
6
  "keywords": [