@kokiito0926/pseudoalias 0.0.4 → 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.
- package/README.md +13 -0
- package/index.js +45 -2
- 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
|
@@ -26,9 +26,18 @@
|
|
|
26
26
|
// >> $ ./index.js --config example.js greetings
|
|
27
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._;
|
|
33
42
|
// console.log(commands);
|
|
34
43
|
|
|
@@ -39,11 +48,45 @@ const completion = args.completion;
|
|
|
39
48
|
// console.log(args);
|
|
40
49
|
// process.exit(0);
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
if (
|
|
51
|
+
if (args.register) {
|
|
52
|
+
if (args.config) {
|
|
53
|
+
const absConfigPath = path.resolve(args.config);
|
|
54
|
+
const configData = fs.readFileSync(absConfigPath, "utf-8");
|
|
55
|
+
|
|
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
|
+
}
|
|
44
75
|
process.exit(0);
|
|
45
76
|
}
|
|
46
77
|
|
|
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
|
+
|
|
47
90
|
const targetPath = path.resolve(targetFile);
|
|
48
91
|
if (!targetPath) {
|
|
49
92
|
process.exit(0);
|