@initx-plugin/cp 0.0.19 → 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/dist/index.d.mts CHANGED
@@ -7,7 +7,7 @@ declare enum CpType {
7
7
  }
8
8
 
9
9
  declare class CpPlugin extends InitxPlugin {
10
- matchers: {
10
+ rules: {
11
11
  matching: string;
12
12
  description: string;
13
13
  }[];
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ declare enum CpType {
7
7
  }
8
8
 
9
9
  declare class CpPlugin extends InitxPlugin {
10
- matchers: {
10
+ rules: {
11
11
  matching: string;
12
12
  description: string;
13
13
  }[];
package/dist/index.mjs CHANGED
@@ -1,79 +1 @@
1
- import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
- import os from 'node:os';
3
- import { resolve } from 'node:path';
4
- import { cwd } from 'node:process';
5
- import { InitxPlugin } from '@initx-plugin/core';
6
- import { log, inquirer, gpgList, c } from '@initx-plugin/utils';
7
- import clipboard from 'clipboardy';
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
- class CpPlugin extends InitxPlugin {
17
- matchers = [
18
- {
19
- matching: "cp",
20
- description: "Copy SSH public key"
21
- }
22
- ];
23
- async handle(_ctx, cpType, ...others) {
24
- if (!cpType || typeof this[cpType] !== "function") {
25
- const typeList = CpType;
26
- log.error(`Please enter the copy type, Available types: ${Object.keys(typeList).map((key) => typeList[key])}`);
27
- return;
28
- }
29
- this[cpType](...others);
30
- }
31
- async [CpType.SSH]() {
32
- const sshDir = resolve(os.homedir(), ".ssh");
33
- if (!existsSync(sshDir)) {
34
- log.error(`SSH directory not found, path: ${sshDir}`);
35
- return;
36
- }
37
- const publicKeysName = readdirSync(sshDir).filter((file) => file.endsWith(".pub"));
38
- if (publicKeysName.length === 0) {
39
- log.error("SSH key not found");
40
- return;
41
- }
42
- let publicKeyName;
43
- if (publicKeysName.length === 1) {
44
- const [firstKey] = publicKeysName;
45
- publicKeyName = firstKey;
46
- } else {
47
- const index = await inquirer.select("Select SSH key", publicKeysName);
48
- publicKeyName = publicKeysName[index];
49
- }
50
- const publicKeyPath = resolve(sshDir, publicKeyName);
51
- const publicKey = readFileSync(publicKeyPath, "utf8");
52
- this.copy(publicKey);
53
- log.success("Key copied to clipboard");
54
- }
55
- async [CpType.GPG]() {
56
- const list = await gpgList();
57
- if (list.length === 0) {
58
- log.error("No GPG keys found");
59
- return;
60
- }
61
- let index = 0;
62
- if (list.length > 1) {
63
- index = await inquirer.select("Select GPG key", list.map(({ key: key2, name, email }) => `${key2} - ${name} <${email}>`));
64
- }
65
- const { key } = list[index];
66
- const result = await c("gpg", ["--armor", "--export", key]);
67
- this.copy(result.content);
68
- log.success("GPG public key copied to clipboard");
69
- }
70
- async [CpType.CWD]() {
71
- this.copy(cwd());
72
- log.success("Current working directory copied to clipboard");
73
- }
74
- copy(content) {
75
- clipboard.writeSync(content);
76
- }
77
- }
78
-
79
- 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.19",
4
+ "version": "0.0.20",
5
5
  "description": "initx plugin, copy some text to clipboard",
6
6
  "author": "imba97",
7
7
  "license": "MIT",
@@ -24,8 +24,8 @@
24
24
  "dist"
25
25
  ],
26
26
  "dependencies": {
27
- "@initx-plugin/core": "^0.0.27",
28
- "@initx-plugin/utils": "^0.0.27",
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": {