@shell-shock/plugin-completions 0.0.18 → 0.1.0

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 (45) hide show
  1. package/README.md +1 -1
  2. package/dist/components/bash.cjs +197 -0
  3. package/dist/components/bash.d.cts +10 -0
  4. package/dist/components/bash.d.cts.map +1 -0
  5. package/dist/components/bash.d.mts +10 -0
  6. package/dist/components/bash.d.mts.map +1 -0
  7. package/dist/components/bash.mjs +198 -0
  8. package/dist/components/bash.mjs.map +1 -0
  9. package/dist/components/index.cjs +5 -1
  10. package/dist/components/index.d.cts +3 -1
  11. package/dist/components/index.d.mts +3 -1
  12. package/dist/components/index.mjs +3 -2
  13. package/dist/components/zsh.cjs +197 -0
  14. package/dist/components/zsh.d.cts +10 -0
  15. package/dist/components/zsh.d.cts.map +1 -0
  16. package/dist/components/zsh.d.mts +10 -0
  17. package/dist/components/zsh.d.mts.map +1 -0
  18. package/dist/components/zsh.mjs +198 -0
  19. package/dist/components/zsh.mjs.map +1 -0
  20. package/dist/index.cjs +13 -3
  21. package/dist/index.d.cts +5 -4
  22. package/dist/index.d.cts.map +1 -1
  23. package/dist/index.d.mts +5 -4
  24. package/dist/index.d.mts.map +1 -1
  25. package/dist/index.mjs +11 -3
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/types/index.cjs +3 -0
  28. package/dist/types/index.d.cts +2 -1
  29. package/dist/types/index.d.mts +2 -1
  30. package/dist/types/index.mjs +3 -1
  31. package/dist/types/shell-type.cjs +6 -0
  32. package/dist/types/shell-type.d.cts +6 -0
  33. package/dist/types/shell-type.d.cts.map +1 -0
  34. package/dist/types/shell-type.d.mts +6 -0
  35. package/dist/types/shell-type.d.mts.map +1 -0
  36. package/dist/types/shell-type.mjs +6 -0
  37. package/dist/types/shell-type.mjs.map +1 -0
  38. package/package.json +68 -7
  39. package/dist/components/command.cjs +0 -59
  40. package/dist/components/command.d.cts +0 -10
  41. package/dist/components/command.d.cts.map +0 -1
  42. package/dist/components/command.d.mts +0 -10
  43. package/dist/components/command.d.mts.map +0 -1
  44. package/dist/components/command.mjs +0 -60
  45. package/dist/components/command.mjs.map +0 -1
package/README.md CHANGED
@@ -27,7 +27,7 @@ This package is part of the ⚡<b>Shell Shock</b> monorepo. The Shell Shock pack
27
27
 
28
28
  <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
29
29
 
30
- [![Version](https://img.shields.io/badge/version-0.0.17-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://stormsoftware.com/projects/shell-shock/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/shell-shock/release.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
30
+ [![Version](https://img.shields.io/badge/version-0.0.18-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://stormsoftware.com/projects/shell-shock/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/shell-shock/release.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
31
31
 
32
32
  <!-- prettier-ignore-start -->
33
33
  <!-- markdownlint-disable -->
@@ -0,0 +1,197 @@
1
+ let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
2
+ let __shell_shock_core_plugin_utils = require("@shell-shock/core/plugin-utils");
3
+ let __alloy_js_core = require("@alloy-js/core");
4
+ let __alloy_js_typescript = require("@alloy-js/typescript");
5
+ let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
6
+ let __powerlines_plugin_alloy_core = require("@powerlines/plugin-alloy/core");
7
+ let __powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
8
+ let __powerlines_plugin_alloy_typescript = require("@powerlines/plugin-alloy/typescript");
9
+ let __powerlines_plugin_alloy_typescript_components_entry_file = require("@powerlines/plugin-alloy/typescript/components/entry-file");
10
+ let __powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
11
+ let __stryke_path = require("@stryke/path");
12
+
13
+ //#region src/components/bash.tsx
14
+ /**
15
+ * The Bash Completions commands' handler wrapper for the Shell Shock project.
16
+ */
17
+ function BashCompletionsCommandEntryFile() {
18
+ const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
19
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_entry_file.EntryFile, {
20
+ get path() {
21
+ return (0, __stryke_path.joinPaths)(context.entryPath, "completions", "bash", "command.ts");
22
+ },
23
+ imports: {
24
+ "node:os": ["os"],
25
+ "node:fs/promises": ["readFile", "writeFile"]
26
+ },
27
+ builtinImports: { "shell-shock:console": [
28
+ "colors",
29
+ "writeLine",
30
+ "success",
31
+ "warn",
32
+ "stripAnsi"
33
+ ] },
34
+ get children() {
35
+ return [
36
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Options for the Bash completions command." }),
37
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
38
+ "export": true,
39
+ name: "BashCompletionsOptions",
40
+ get children() {
41
+ return [
42
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
43
+ heading: "The path to write the completion script to.",
44
+ get children() {
45
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: `If no extension is provided, the \`.bash\` extension will be used.` }), (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
46
+ get type() {
47
+ return __powerlines_deepkit_vendor_type.ReflectionKind.string;
48
+ },
49
+ get defaultValue() {
50
+ return `${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}-completions.bash`;
51
+ }
52
+ })];
53
+ }
54
+ }),
55
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
56
+ name: "script",
57
+ optional: true,
58
+ type: "string | true"
59
+ }),
60
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
61
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
62
+ heading: "The Bash configuration file to append the completion script to.",
63
+ get children() {
64
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: `The generated completion script will be appended to the specified configuration file. Possible values for the Bash configuration file include: \\n- \`~/.bashrc\` \\n- \`~/.bash_profile\`` }), (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
65
+ get type() {
66
+ return __powerlines_deepkit_vendor_type.ReflectionKind.string;
67
+ },
68
+ defaultValue: "~/.bashrc"
69
+ })];
70
+ }
71
+ }),
72
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
73
+ name: "config",
74
+ optional: true,
75
+ type: "string | true"
76
+ })
77
+ ];
78
+ }
79
+ }),
80
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
81
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Entry point for the Bash completions command." }),
82
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
83
+ "export": true,
84
+ "default": true,
85
+ async: true,
86
+ name: "handler",
87
+ parameters: [{
88
+ name: "options",
89
+ type: "BashCompletionsOptions"
90
+ }],
91
+ get children() {
92
+ return [
93
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
94
+ "const": true,
95
+ name: "completions",
96
+ type: "string",
97
+ get initializer() {
98
+ return __alloy_js_core.code`colors.white(\`\${colors.gray("###-begin-${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}-completions-###")}
99
+
100
+ \${colors.gray(\`
101
+ # \${colors.bold("${(0, __shell_shock_core_plugin_utils.getAppTitle)(context)} Bash CLI command completion script")}
102
+ #
103
+ # \${colors.bold("Installation:")} ${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} completions bash --config ~/.bashrc or ${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} completions bash --script or ${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} completions bash >> ~/.bashrc or ${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} completions bash >> ~/.bash_profile on OSX. \`
104
+ )}
105
+ \${colors.cyan("_${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}_completions()")}
106
+ {
107
+ local cur_word args type_list
108
+
109
+ cur_word="\\\${COMP_WORDS[COMP_CWORD]}"
110
+ args=("\\\${COMP_WORDS[@]}")
111
+
112
+ \${colors.gray("# Ask ${(0, __shell_shock_core_plugin_utils.getAppTitle)(context)} CLI to generate completions.")}
113
+ mapfile -t type_list < <(${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} --get-completions "\\\${args[@]}")
114
+ mapfile -t COMPREPLY < <(compgen -W "$( printf '%q ' "\\\${type_list[@]}" )" -- "\\\${cur_word}" |
115
+ awk '/ / { print "\\\\""$0"\\\\"" } /^[^ ]+$/ { print $0 }')
116
+
117
+ \${colors.gray("# if no match was found, fall back to filename completion")}
118
+ if [ \\\${#COMPREPLY[@]} -eq 0 ]; then
119
+ COMPREPLY=()
120
+ fi
121
+
122
+ return 0
123
+ }
124
+ complete -o bashdefault -o default -F _${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}_completions ${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}
125
+
126
+ \${colors.gray("###-end-${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}-completions-###")}
127
+ \`); `;
128
+ }
129
+ }),
130
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
131
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
132
+ condition: __alloy_js_core.code`options.config`,
133
+ get children() {
134
+ return [
135
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
136
+ "let": true,
137
+ name: "configFilePath",
138
+ type: "string",
139
+ initializer: __alloy_js_core.code`options.config === true ? "~/.bashrc" : options.config`
140
+ }),
141
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
142
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
143
+ condition: __alloy_js_core.code`configFilePath.startsWith("~")`,
144
+ children: __alloy_js_core.code`configFilePath = join(os.homedir(), configFilePath.replace("~", "")); `
145
+ }),
146
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
147
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
148
+ "let": true,
149
+ name: "configFileContent",
150
+ type: "string",
151
+ initializer: __alloy_js_core.code`"";`
152
+ }),
153
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
154
+ (0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`try {
155
+ configFileContent = await readFile(configFilePath, "utf8");
156
+ } catch (error) {
157
+ if (error.code === "ENOENT") {
158
+ // If the file doesn't exist, we can create it later when writing the completion script.
159
+ warn(\`Configuration file \${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\`);
160
+ } else {
161
+ return { error };
162
+ }
163
+ }
164
+
165
+ await writeFile(configFilePath, \`\${configFileContent}\\n\\n\${stripAnsi(completions)}\`);
166
+
167
+ success(\`${(0, __shell_shock_core_plugin_utils.getAppTitle)(context)} Bash completion script has been generated and appended to \${colors.bold(configFilePath)}. Please restart your terminal or run \`source \${configFilePath}\` to apply the changes.\`); `)
168
+ ];
169
+ }
170
+ }),
171
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
172
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
173
+ condition: __alloy_js_core.code`options.script`,
174
+ get children() {
175
+ return __alloy_js_core.code`const outputPath = options.script === true ? "${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}-completions.bash" : options.script;
176
+ await writeFile(outputPath, stripAnsi(completions));
177
+
178
+ success(\`${(0, __shell_shock_core_plugin_utils.getAppTitle)(context)} Bash completion script has been generated at \${colors.bold(outputPath)}.\`);`;
179
+ }
180
+ }),
181
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
182
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
183
+ condition: __alloy_js_core.code`!options.config && !options.script`,
184
+ children: __alloy_js_core.code`writeLine(" ------------------------------------------------- ");
185
+ writeLine(completions);
186
+ writeLine(" ------------------------------------------------- ");`
187
+ })
188
+ ];
189
+ }
190
+ })
191
+ ];
192
+ }
193
+ });
194
+ }
195
+
196
+ //#endregion
197
+ exports.BashCompletionsCommandEntryFile = BashCompletionsCommandEntryFile;
@@ -0,0 +1,10 @@
1
+ import * as _alloy_js_core0 from "@alloy-js/core";
2
+
3
+ //#region src/components/bash.d.ts
4
+ /**
5
+ * The Bash Completions commands' handler wrapper for the Shell Shock project.
6
+ */
7
+ declare function BashCompletionsCommandEntryFile(): _alloy_js_core0.Children;
8
+ //#endregion
9
+ export { BashCompletionsCommandEntryFile };
10
+ //# sourceMappingURL=bash.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.d.cts","names":[],"sources":["../../src/components/bash.tsx"],"sourcesContent":[],"mappings":";;;;;;AA0CgB,iBAAA,+BAAA,CAAA,CAA+B,EAAA,eAAA,CAAA,QAAA"}
@@ -0,0 +1,10 @@
1
+ import * as _alloy_js_core0 from "@alloy-js/core";
2
+
3
+ //#region src/components/bash.d.ts
4
+ /**
5
+ * The Bash Completions commands' handler wrapper for the Shell Shock project.
6
+ */
7
+ declare function BashCompletionsCommandEntryFile(): _alloy_js_core0.Children;
8
+ //#endregion
9
+ export { BashCompletionsCommandEntryFile };
10
+ //# sourceMappingURL=bash.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.d.mts","names":[],"sources":["../../src/components/bash.tsx"],"sourcesContent":[],"mappings":";;;;;;AA0CgB,iBAAA,+BAAA,CAAA,CAA+B,EAAA,eAAA,CAAA,QAAA"}
@@ -0,0 +1,198 @@
1
+ import { createComponent, memo } from "@alloy-js/core/jsx-runtime";
2
+ import { getAppBin, getAppTitle } from "@shell-shock/core/plugin-utils";
3
+ import { code } from "@alloy-js/core";
4
+ import { FunctionDeclaration, IfStatement, InterfaceDeclaration, VarDeclaration } from "@alloy-js/typescript";
5
+ import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
6
+ import { Spacing } from "@powerlines/plugin-alloy/core";
7
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
8
+ import { InterfaceMember } from "@powerlines/plugin-alloy/typescript";
9
+ import { EntryFile } from "@powerlines/plugin-alloy/typescript/components/entry-file";
10
+ import { TSDoc, TSDocDefaultValue, TSDocRemarks } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
11
+ import { joinPaths } from "@stryke/path";
12
+
13
+ //#region src/components/bash.tsx
14
+ /**
15
+ * The Bash Completions commands' handler wrapper for the Shell Shock project.
16
+ */
17
+ function BashCompletionsCommandEntryFile() {
18
+ const context = usePowerlines();
19
+ return createComponent(EntryFile, {
20
+ get path() {
21
+ return joinPaths(context.entryPath, "completions", "bash", "command.ts");
22
+ },
23
+ imports: {
24
+ "node:os": ["os"],
25
+ "node:fs/promises": ["readFile", "writeFile"]
26
+ },
27
+ builtinImports: { "shell-shock:console": [
28
+ "colors",
29
+ "writeLine",
30
+ "success",
31
+ "warn",
32
+ "stripAnsi"
33
+ ] },
34
+ get children() {
35
+ return [
36
+ createComponent(TSDoc, { heading: "Options for the Bash completions command." }),
37
+ createComponent(InterfaceDeclaration, {
38
+ "export": true,
39
+ name: "BashCompletionsOptions",
40
+ get children() {
41
+ return [
42
+ createComponent(TSDoc, {
43
+ heading: "The path to write the completion script to.",
44
+ get children() {
45
+ return [createComponent(TSDocRemarks, { children: `If no extension is provided, the \`.bash\` extension will be used.` }), createComponent(TSDocDefaultValue, {
46
+ get type() {
47
+ return ReflectionKind.string;
48
+ },
49
+ get defaultValue() {
50
+ return `${getAppBin(context)}-completions.bash`;
51
+ }
52
+ })];
53
+ }
54
+ }),
55
+ createComponent(InterfaceMember, {
56
+ name: "script",
57
+ optional: true,
58
+ type: "string | true"
59
+ }),
60
+ createComponent(Spacing, {}),
61
+ createComponent(TSDoc, {
62
+ heading: "The Bash configuration file to append the completion script to.",
63
+ get children() {
64
+ return [createComponent(TSDocRemarks, { children: `The generated completion script will be appended to the specified configuration file. Possible values for the Bash configuration file include: \\n- \`~/.bashrc\` \\n- \`~/.bash_profile\`` }), createComponent(TSDocDefaultValue, {
65
+ get type() {
66
+ return ReflectionKind.string;
67
+ },
68
+ defaultValue: "~/.bashrc"
69
+ })];
70
+ }
71
+ }),
72
+ createComponent(InterfaceMember, {
73
+ name: "config",
74
+ optional: true,
75
+ type: "string | true"
76
+ })
77
+ ];
78
+ }
79
+ }),
80
+ createComponent(Spacing, {}),
81
+ createComponent(TSDoc, { heading: "Entry point for the Bash completions command." }),
82
+ createComponent(FunctionDeclaration, {
83
+ "export": true,
84
+ "default": true,
85
+ async: true,
86
+ name: "handler",
87
+ parameters: [{
88
+ name: "options",
89
+ type: "BashCompletionsOptions"
90
+ }],
91
+ get children() {
92
+ return [
93
+ createComponent(VarDeclaration, {
94
+ "const": true,
95
+ name: "completions",
96
+ type: "string",
97
+ get initializer() {
98
+ return code`colors.white(\`\${colors.gray("###-begin-${getAppBin(context)}-completions-###")}
99
+
100
+ \${colors.gray(\`
101
+ # \${colors.bold("${getAppTitle(context)} Bash CLI command completion script")}
102
+ #
103
+ # \${colors.bold("Installation:")} ${getAppBin(context)} completions bash --config ~/.bashrc or ${getAppBin(context)} completions bash --script or ${getAppBin(context)} completions bash >> ~/.bashrc or ${getAppBin(context)} completions bash >> ~/.bash_profile on OSX. \`
104
+ )}
105
+ \${colors.cyan("_${getAppBin(context)}_completions()")}
106
+ {
107
+ local cur_word args type_list
108
+
109
+ cur_word="\\\${COMP_WORDS[COMP_CWORD]}"
110
+ args=("\\\${COMP_WORDS[@]}")
111
+
112
+ \${colors.gray("# Ask ${getAppTitle(context)} CLI to generate completions.")}
113
+ mapfile -t type_list < <(${getAppBin(context)} --get-completions "\\\${args[@]}")
114
+ mapfile -t COMPREPLY < <(compgen -W "$( printf '%q ' "\\\${type_list[@]}" )" -- "\\\${cur_word}" |
115
+ awk '/ / { print "\\\\""$0"\\\\"" } /^[^ ]+$/ { print $0 }')
116
+
117
+ \${colors.gray("# if no match was found, fall back to filename completion")}
118
+ if [ \\\${#COMPREPLY[@]} -eq 0 ]; then
119
+ COMPREPLY=()
120
+ fi
121
+
122
+ return 0
123
+ }
124
+ complete -o bashdefault -o default -F _${getAppBin(context)}_completions ${getAppBin(context)}
125
+
126
+ \${colors.gray("###-end-${getAppBin(context)}-completions-###")}
127
+ \`); `;
128
+ }
129
+ }),
130
+ createComponent(Spacing, {}),
131
+ createComponent(IfStatement, {
132
+ condition: code`options.config`,
133
+ get children() {
134
+ return [
135
+ createComponent(VarDeclaration, {
136
+ "let": true,
137
+ name: "configFilePath",
138
+ type: "string",
139
+ initializer: code`options.config === true ? "~/.bashrc" : options.config`
140
+ }),
141
+ createComponent(Spacing, {}),
142
+ createComponent(IfStatement, {
143
+ condition: code`configFilePath.startsWith("~")`,
144
+ children: code`configFilePath = join(os.homedir(), configFilePath.replace("~", "")); `
145
+ }),
146
+ createComponent(Spacing, {}),
147
+ createComponent(VarDeclaration, {
148
+ "let": true,
149
+ name: "configFileContent",
150
+ type: "string",
151
+ initializer: code`"";`
152
+ }),
153
+ createComponent(Spacing, {}),
154
+ memo(() => code`try {
155
+ configFileContent = await readFile(configFilePath, "utf8");
156
+ } catch (error) {
157
+ if (error.code === "ENOENT") {
158
+ // If the file doesn't exist, we can create it later when writing the completion script.
159
+ warn(\`Configuration file \${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\`);
160
+ } else {
161
+ return { error };
162
+ }
163
+ }
164
+
165
+ await writeFile(configFilePath, \`\${configFileContent}\\n\\n\${stripAnsi(completions)}\`);
166
+
167
+ success(\`${getAppTitle(context)} Bash completion script has been generated and appended to \${colors.bold(configFilePath)}. Please restart your terminal or run \`source \${configFilePath}\` to apply the changes.\`); `)
168
+ ];
169
+ }
170
+ }),
171
+ createComponent(Spacing, {}),
172
+ createComponent(IfStatement, {
173
+ condition: code`options.script`,
174
+ get children() {
175
+ return code`const outputPath = options.script === true ? "${getAppBin(context)}-completions.bash" : options.script;
176
+ await writeFile(outputPath, stripAnsi(completions));
177
+
178
+ success(\`${getAppTitle(context)} Bash completion script has been generated at \${colors.bold(outputPath)}.\`);`;
179
+ }
180
+ }),
181
+ createComponent(Spacing, {}),
182
+ createComponent(IfStatement, {
183
+ condition: code`!options.config && !options.script`,
184
+ children: code`writeLine(" ------------------------------------------------- ");
185
+ writeLine(completions);
186
+ writeLine(" ------------------------------------------------- ");`
187
+ })
188
+ ];
189
+ }
190
+ })
191
+ ];
192
+ }
193
+ });
194
+ }
195
+
196
+ //#endregion
197
+ export { BashCompletionsCommandEntryFile };
198
+ //# sourceMappingURL=bash.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.mjs","names":["code","FunctionDeclaration","IfStatement","InterfaceDeclaration","VarDeclaration","ReflectionKind","Spacing","usePowerlines","InterfaceMember","EntryFile","TSDoc","TSDocDefaultValue","TSDocRemarks","getAppBin","getAppTitle","joinPaths","BashCompletionsCommandEntryFile","context","_$createComponent","path","entryPath","imports","builtinImports","children","heading","name","type","string","defaultValue","optional","async","parameters","initializer","condition","_$memo"],"sources":["../../src/components/bash.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code } from \"@alloy-js/core\";\nimport {\n FunctionDeclaration,\n IfStatement,\n InterfaceDeclaration,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport { InterfaceMember } from \"@powerlines/plugin-alloy/typescript\";\nimport { EntryFile } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport {\n TSDoc,\n TSDocDefaultValue,\n TSDocRemarks\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport { getAppBin, getAppTitle } from \"@shell-shock/core/plugin-utils\";\nimport { joinPaths } from \"@stryke/path\";\nimport type { CompletionsPluginContext } from \"../types/plugin\";\n\n/**\n * The Bash Completions commands' handler wrapper for the Shell Shock project.\n */\nexport function BashCompletionsCommandEntryFile() {\n const context = usePowerlines<CompletionsPluginContext>();\n\n return (\n <EntryFile\n path={joinPaths(context.entryPath, \"completions\", \"bash\", \"command.ts\")}\n imports={{\n \"node:os\": [\"os\"],\n \"node:fs/promises\": [\"readFile\", \"writeFile\"]\n }}\n builtinImports={{\n \"shell-shock:console\": [\n \"colors\",\n \"writeLine\",\n \"success\",\n \"warn\",\n \"stripAnsi\"\n ]\n }}>\n <TSDoc heading=\"Options for the Bash completions command.\" />\n <InterfaceDeclaration export name=\"BashCompletionsOptions\">\n <TSDoc heading=\"The path to write the completion script to.\">\n <TSDocRemarks>{`If no extension is provided, the \\`.bash\\` extension will be used.`}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue={`${getAppBin(context)}-completions.bash`}\n />\n </TSDoc>\n <InterfaceMember name=\"script\" optional type=\"string | true\" />\n <Spacing />\n <TSDoc heading=\"The Bash configuration file to append the completion script to.\">\n <TSDocRemarks>{`The generated completion script will be appended to the specified configuration file. Possible values for the Bash configuration file include: \\\\n- \\`~/.bashrc\\` \\\\n- \\`~/.bash_profile\\``}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue=\"~/.bashrc\"\n />\n </TSDoc>\n <InterfaceMember name=\"config\" optional type=\"string | true\" />\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc heading=\"Entry point for the Bash completions command.\"></TSDoc>\n <FunctionDeclaration\n export\n default\n async\n name=\"handler\"\n parameters={[{ name: \"options\", type: \"BashCompletionsOptions\" }]}>\n <VarDeclaration\n const\n name=\"completions\"\n type=\"string\"\n initializer={code`colors.white(\\`\\${colors.gray(\"###-begin-${getAppBin(context)}-completions-###\")}\n\n\\${colors.gray(\\`\n# \\${colors.bold(\"${getAppTitle(context)} Bash CLI command completion script\")}\n#\n# \\${colors.bold(\"Installation:\")} ${getAppBin(context)} completions bash --config ~/.bashrc or ${getAppBin(context)} completions bash --script or ${getAppBin(context)} completions bash >> ~/.bashrc or ${getAppBin(context)} completions bash >> ~/.bash_profile on OSX. \\`\n)}\n\\${colors.cyan(\"_${getAppBin(context)}_completions()\")}\n{\n local cur_word args type_list\n\n cur_word=\"\\\\\\${COMP_WORDS[COMP_CWORD]}\"\n args=(\"\\\\\\${COMP_WORDS[@]}\")\n\n \\${colors.gray(\"# Ask ${getAppTitle(context)} CLI to generate completions.\")}\n mapfile -t type_list < <(${getAppBin(context)} --get-completions \"\\\\\\${args[@]}\")\n mapfile -t COMPREPLY < <(compgen -W \"$( printf '%q ' \"\\\\\\${type_list[@]}\" )\" -- \"\\\\\\${cur_word}\" |\n awk '/ / { print \"\\\\\\\\\"\"$0\"\\\\\\\\\"\" } /^[^ ]+$/ { print $0 }')\n\n \\${colors.gray(\"# if no match was found, fall back to filename completion\")}\n if [ \\\\\\${#COMPREPLY[@]} -eq 0 ]; then\n COMPREPLY=()\n fi\n\n return 0\n}\ncomplete -o bashdefault -o default -F _${getAppBin(context)}_completions ${getAppBin(context)}\n\n\\${colors.gray(\"###-end-${getAppBin(context)}-completions-###\")}\n\\`); `}\n />\n <Spacing />\n <IfStatement condition={code`options.config`}>\n <VarDeclaration\n let\n name=\"configFilePath\"\n type=\"string\"\n initializer={code`options.config === true ? \"~/.bashrc\" : options.config`}\n />\n <Spacing />\n <IfStatement condition={code`configFilePath.startsWith(\"~\")`}>\n {code`configFilePath = join(os.homedir(), configFilePath.replace(\"~\", \"\")); `}\n </IfStatement>\n <Spacing />\n <VarDeclaration\n let\n name=\"configFileContent\"\n type=\"string\"\n initializer={code`\"\";`}\n />\n <Spacing />\n {code`try {\n configFileContent = await readFile(configFilePath, \"utf8\");\n } catch (error) {\n if (error.code === \"ENOENT\") {\n // If the file doesn't exist, we can create it later when writing the completion script.\n warn(\\`Configuration file \\${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\\`);\n } else {\n return { error };\n }\n }\n\n await writeFile(configFilePath, \\`\\${configFileContent}\\\\n\\\\n\\${stripAnsi(completions)}\\`);\n\n success(\\`${getAppTitle(context)} Bash completion script has been generated and appended to \\${colors.bold(configFilePath)}. Please restart your terminal or run \\`source \\${configFilePath}\\` to apply the changes.\\`); `}\n </IfStatement>\n <Spacing />\n <IfStatement condition={code`options.script`}>\n {code`const outputPath = options.script === true ? \"${getAppBin(context)}-completions.bash\" : options.script;\n await writeFile(outputPath, stripAnsi(completions));\n\n success(\\`${getAppTitle(context)} Bash completion script has been generated at \\${colors.bold(outputPath)}.\\`);`}\n </IfStatement>\n <Spacing />\n <IfStatement condition={code`!options.config && !options.script`}>\n {code`writeLine(\" ------------------------------------------------- \");\n writeLine(completions);\n writeLine(\" ------------------------------------------------- \");`}\n </IfStatement>\n </FunctionDeclaration>\n </EntryFile>\n );\n}\n"],"mappings":"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"}
@@ -1 +1,5 @@
1
- const require_command = require('./command.cjs');
1
+ const require_components_bash = require('./bash.cjs');
2
+ const require_components_zsh = require('./zsh.cjs');
3
+
4
+ exports.BashCompletionsCommandEntryFile = require_components_bash.BashCompletionsCommandEntryFile;
5
+ exports.ZshCompletionsCommandEntryFile = require_components_zsh.ZshCompletionsCommandEntryFile;
@@ -1 +1,3 @@
1
- import { CommandHandlerWrapper } from "./command.cjs";
1
+ import { BashCompletionsCommandEntryFile } from "./bash.cjs";
2
+ import { ZshCompletionsCommandEntryFile } from "./zsh.cjs";
3
+ export { BashCompletionsCommandEntryFile, ZshCompletionsCommandEntryFile };
@@ -1 +1,3 @@
1
- import { CommandHandlerWrapper } from "./command.mjs";
1
+ import { BashCompletionsCommandEntryFile } from "./bash.mjs";
2
+ import { ZshCompletionsCommandEntryFile } from "./zsh.mjs";
3
+ export { BashCompletionsCommandEntryFile, ZshCompletionsCommandEntryFile };
@@ -1,3 +1,4 @@
1
- import { CommandHandlerWrapper } from "./command.mjs";
1
+ import { BashCompletionsCommandEntryFile } from "./bash.mjs";
2
+ import { ZshCompletionsCommandEntryFile } from "./zsh.mjs";
2
3
 
3
- export { };
4
+ export { BashCompletionsCommandEntryFile, ZshCompletionsCommandEntryFile };