@kokiito0926/pseudoalias 0.0.4 → 0.0.6
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 +60 -5
- package/index.js +45 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
##
|
|
1
|
+
## pseudoalias
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
.bashrcなどにエイリアスを書くよりも、JavaScript
|
|
3
|
+
pseudoaliasは、擬似的なエイリアスを作成することができるコマンドラインのツールです。
|
|
4
|
+
.bashrcなどにエイリアスを書くよりも、JavaScriptでエイリアスを書けるようになるので、書きやすいような気がします。
|
|
5
5
|
|
|
6
6
|
## インストール
|
|
7
7
|
|
|
@@ -9,15 +9,70 @@
|
|
|
9
9
|
$ npm install --global @kokiito0926/pseudoalias
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## 使用方法
|
|
13
|
+
|
|
14
|
+
設定のファイルにエイリアスを記述します。
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
export const greetings = async () => {
|
|
18
|
+
console.log("Hello, world!");
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const addition = async (one, two) => {
|
|
22
|
+
console.log(Number(one) + Number(two));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const subtraction = async (one, two) => {
|
|
26
|
+
console.log(Number(one) - Number(two));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const multiplication = async (one, two) => {
|
|
30
|
+
console.log(Number(one) * Number(two));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const division = async (one, two) => {
|
|
34
|
+
console.log(Number(one) / Number(two));
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
--configのオプションに設定のファイルを指定します。
|
|
39
|
+
そうしたら、定義されているエイリアスを実行することができます。
|
|
13
40
|
|
|
14
41
|
```bash
|
|
15
|
-
$ pseudoalias --config ./example.js
|
|
16
42
|
$ pseudoalias --config ./example.js greetings
|
|
17
43
|
$ pseudoalias --config ./example.js addition 1 2
|
|
18
44
|
$ pseudoalias --config ./example.js subtraction 2 1
|
|
19
45
|
```
|
|
20
46
|
|
|
47
|
+
エイリアスを書かずに実行した場合、エイリアスの一覧が表示されます。
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
$ pseudoalias --config ./example.js
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
--registerのオプションを用いると、ホームディレクトリに設定のファイルが保存されます。
|
|
54
|
+
それ以降は、--configのオプションを用いなくても、定義されているエイリアスを実行することができます。
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
$ pseudoalias --config ./example.js --register
|
|
58
|
+
|
|
59
|
+
$ pseudoalias greetings
|
|
60
|
+
$ pseudoalias addition 1 2
|
|
61
|
+
$ pseudoalias subtraction 2 1
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
--unregisterのオプションを用いると、ホームディレクトリから設定のファイルを削除します。
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
$ pseudoalias --unregister
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
下記のコマンドを.bashrcなどに追記すると、入力補完が効くようになります。
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
$ complete -C "pseudoalias --completion" -o default pseudoalias
|
|
74
|
+
```
|
|
75
|
+
|
|
21
76
|
## ライセンス
|
|
22
77
|
|
|
23
78
|
[MIT](LICENSE)
|
package/index.js
CHANGED
|
@@ -26,9 +26,17 @@
|
|
|
26
26
|
// >> $ ./index.js --config example.js greetings
|
|
27
27
|
// >> $ ./index.js --config example.js addition 1 2
|
|
28
28
|
|
|
29
|
-
|
|
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, minimist, fs, path, argv } from "zx";
|
|
30
35
|
import { pathToFileURL } from "node:url";
|
|
31
36
|
|
|
37
|
+
const CONFIG_DIR = path.join(os.homedir(), ".pseudoalias");
|
|
38
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, "config.js");
|
|
39
|
+
|
|
32
40
|
const commands = argv._;
|
|
33
41
|
// console.log(commands);
|
|
34
42
|
|
|
@@ -39,11 +47,45 @@ const completion = args.completion;
|
|
|
39
47
|
// console.log(args);
|
|
40
48
|
// process.exit(0);
|
|
41
49
|
|
|
42
|
-
|
|
43
|
-
if (
|
|
50
|
+
if (args.register) {
|
|
51
|
+
if (args.config) {
|
|
52
|
+
const absConfigPath = path.resolve(args.config);
|
|
53
|
+
const configData = fs.readFileSync(absConfigPath, "utf-8");
|
|
54
|
+
|
|
55
|
+
await fs.ensureDir(CONFIG_DIR);
|
|
56
|
+
|
|
57
|
+
await fs.writeFile(CONFIG_FILE, configData, "utf-8");
|
|
58
|
+
|
|
59
|
+
console.log(`Success: Registered config path to ${absConfigPath}`);
|
|
60
|
+
console.log(`Stored in: ${CONFIG_FILE}`);
|
|
61
|
+
} else {
|
|
62
|
+
console.error("Error: --config is required with --register");
|
|
63
|
+
}
|
|
64
|
+
process.exit(0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (args.unregister) {
|
|
68
|
+
if (await fs.exists(CONFIG_DIR)) {
|
|
69
|
+
await fs.remove(CONFIG_DIR);
|
|
70
|
+
console.log("Success: Unregistered and removed configuration.");
|
|
71
|
+
} else {
|
|
72
|
+
console.log("Notice: No configuration found to unregister.");
|
|
73
|
+
}
|
|
44
74
|
process.exit(0);
|
|
45
75
|
}
|
|
46
76
|
|
|
77
|
+
let targetFile = config;
|
|
78
|
+
|
|
79
|
+
if (!targetFile) {
|
|
80
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
81
|
+
targetFile = CONFIG_FILE;
|
|
82
|
+
} else {
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// console.log(targetFile);
|
|
87
|
+
// process.exit(0);
|
|
88
|
+
|
|
47
89
|
const targetPath = path.resolve(targetFile);
|
|
48
90
|
if (!targetPath) {
|
|
49
91
|
process.exit(0);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokiito0926/pseudoalias",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "擬似的なエイリアスを作成することができるコマンドラインのツールです。",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cli",
|
|
8
8
|
"bash",
|