@initx-plugin/cp 0.0.18 → 0.0.20
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 +6 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -88
- package/package.json +11 -11
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,88 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { cwd } from 'node:process';
|
|
3
|
-
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
4
|
-
import { resolve } from 'node:path';
|
|
5
|
-
import clipboard from 'clipboardy';
|
|
6
|
-
import { InitxPlugin } from '@initx-plugin/core';
|
|
7
|
-
import { log, inquirer, gpgList, c } from '@initx-plugin/utils';
|
|
8
|
-
|
|
9
|
-
var CpType = /* @__PURE__ */ ((CpType2) => {
|
|
10
|
-
CpType2["SSH"] = "ssh";
|
|
11
|
-
CpType2["GPG"] = "gpg";
|
|
12
|
-
CpType2["CWD"] = "cwd";
|
|
13
|
-
return CpType2;
|
|
14
|
-
})(CpType || {});
|
|
15
|
-
|
|
16
|
-
var __defProp = Object.defineProperty;
|
|
17
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
18
|
-
var __publicField = (obj, key, value) => {
|
|
19
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
20
|
-
return value;
|
|
21
|
-
};
|
|
22
|
-
class CpPlugin extends InitxPlugin {
|
|
23
|
-
constructor() {
|
|
24
|
-
super(...arguments);
|
|
25
|
-
__publicField(this, "matchers", [
|
|
26
|
-
{
|
|
27
|
-
matching: "cp",
|
|
28
|
-
description: "Copy SSH public key"
|
|
29
|
-
}
|
|
30
|
-
]);
|
|
31
|
-
}
|
|
32
|
-
async handle(_ctx, cpType, ...others) {
|
|
33
|
-
if (!cpType || typeof this[cpType] !== "function") {
|
|
34
|
-
const typeList = CpType;
|
|
35
|
-
log.error(`Please enter the copy type, Available types: ${Object.keys(typeList).map((key) => typeList[key])}`);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
this[cpType](...others);
|
|
39
|
-
}
|
|
40
|
-
async [CpType.SSH]() {
|
|
41
|
-
const sshDir = resolve(os.homedir(), ".ssh");
|
|
42
|
-
if (!existsSync(sshDir)) {
|
|
43
|
-
log.error(`SSH directory not found, path: ${sshDir}`);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const publicKeysName = readdirSync(sshDir).filter((file) => file.endsWith(".pub"));
|
|
47
|
-
if (publicKeysName.length === 0) {
|
|
48
|
-
log.error("SSH key not found");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
let publicKeyName;
|
|
52
|
-
if (publicKeysName.length === 1) {
|
|
53
|
-
const [firstKey] = publicKeysName;
|
|
54
|
-
publicKeyName = firstKey;
|
|
55
|
-
} else {
|
|
56
|
-
const index = await inquirer.select("Select SSH key", publicKeysName);
|
|
57
|
-
publicKeyName = publicKeysName[index];
|
|
58
|
-
}
|
|
59
|
-
const publicKeyPath = resolve(sshDir, publicKeyName);
|
|
60
|
-
const publicKey = readFileSync(publicKeyPath, "utf8");
|
|
61
|
-
this.copy(publicKey);
|
|
62
|
-
log.success("Key copied to clipboard");
|
|
63
|
-
}
|
|
64
|
-
async [CpType.GPG]() {
|
|
65
|
-
const list = await gpgList();
|
|
66
|
-
if (list.length === 0) {
|
|
67
|
-
log.error("No GPG keys found");
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
let index = 0;
|
|
71
|
-
if (list.length > 1) {
|
|
72
|
-
index = await inquirer.select("Select GPG key", list.map(({ key: key2, name, email }) => `${key2} - ${name} <${email}>`));
|
|
73
|
-
}
|
|
74
|
-
const { key } = list[index];
|
|
75
|
-
const result = await c("gpg", ["--armor", "--export", key]);
|
|
76
|
-
this.copy(result.content);
|
|
77
|
-
log.success("GPG public key copied to clipboard");
|
|
78
|
-
}
|
|
79
|
-
async [CpType.CWD]() {
|
|
80
|
-
this.copy(cwd());
|
|
81
|
-
log.success("Current working directory copied to clipboard");
|
|
82
|
-
}
|
|
83
|
-
copy(content) {
|
|
84
|
-
clipboard.writeSync(content);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { CpPlugin as default };
|
|
1
|
+
import{existsSync as d,readdirSync as f,readFileSync as m}from"node:fs";import u from"node:os";import{resolve as a}from"node:path";import{cwd as S}from"node:process";import{InitxPlugin as h}from"@initx-plugin/core";import{log as i,inquirer as y,gpgList as g,c as k}from"@initx-plugin/utils";import G from"clipboardy";var p=(s=>(s.SSH="ssh",s.GPG="gpg",s.CWD="cwd",s))(p||{});class b extends h{rules=[{matching:"cp",description:"Copy SSH public key"}];async handle(e,t,...r){if(!t||typeof this[t]!="function"){const c=p;i.error(`Please enter the copy type, Available types: ${Object.keys(c).map(n=>c[n])}`);return}this[t](...r)}async[p.SSH](){const e=a(u.homedir(),".ssh");if(!d(e)){i.error(`SSH directory not found, path: ${e}`);return}const t=f(e).filter(o=>o.endsWith(".pub"));if(t.length===0){i.error("SSH key not found");return}let r;if(t.length===1){const[o]=t;r=o}else{const o=await y.select("Select SSH key",t);r=t[o]}const c=a(e,r),n=m(c,"utf8");this.copy(n),i.success("Key copied to clipboard")}async[p.GPG](){const e=await g();if(e.length===0){i.error("No GPG keys found");return}let t=0;e.length>1&&(t=await y.select("Select GPG key",e.map(({key:n,name:o,email:l})=>`${n} - ${o} <${l}>`)));const{key:r}=e[t],c=await k("gpg",["--armor","--export",r]);this.copy(c.content),i.success("GPG public key copied to clipboard")}async[p.CWD](){this.copy(S()),i.success("Current working directory copied to clipboard")}copy(e){G.writeSync(e)}}export{b as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@initx-plugin/cp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.20",
|
|
5
5
|
"description": "initx plugin, copy some text to clipboard",
|
|
6
6
|
"author": "imba97",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,20 +24,20 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@initx-plugin/core": "^0.0.
|
|
28
|
-
"@initx-plugin/utils": "^0.0.
|
|
27
|
+
"@initx-plugin/core": "^0.0.28",
|
|
28
|
+
"@initx-plugin/utils": "^0.0.28",
|
|
29
29
|
"clipboardy": "^4.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@imba97/eslint-config": "^0.0.
|
|
33
|
-
"@types/node": "^22.
|
|
34
|
-
"bumpp": "^9.
|
|
35
|
-
"eslint": "^9.
|
|
36
|
-
"lint-staged": "^15.
|
|
32
|
+
"@imba97/eslint-config": "^0.0.5",
|
|
33
|
+
"@types/node": "^22.10.2",
|
|
34
|
+
"bumpp": "^9.9.2",
|
|
35
|
+
"eslint": "^9.17.0",
|
|
36
|
+
"lint-staged": "^15.3.0",
|
|
37
37
|
"simple-git-hooks": "^2.11.1",
|
|
38
|
-
"typescript": "5.
|
|
39
|
-
"unbuild": "^
|
|
40
|
-
"vitest": "^2.1.
|
|
38
|
+
"typescript": "^5.7.2",
|
|
39
|
+
"unbuild": "^3.1.0",
|
|
40
|
+
"vitest": "^2.1.8"
|
|
41
41
|
},
|
|
42
42
|
"simple-git-hooks": {
|
|
43
43
|
"pre-commit": "pnpm lint-staged"
|