@shell-shock/plugin-completions 0.2.22 → 0.2.24

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 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.2.16-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.2.22-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 -->
@@ -4,7 +4,6 @@ const require_helpers_completion_directive_constants = require('../helpers/compl
4
4
  require('../helpers/index.cjs');
5
5
  let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
6
6
  let _shell_shock_core_plugin_utils = require("@shell-shock/core/plugin-utils");
7
- let _stryke_path = require("@stryke/path");
8
7
  let _alloy_js_core = require("@alloy-js/core");
9
8
  let _alloy_js_typescript = require("@alloy-js/typescript");
10
9
  let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
@@ -12,6 +11,7 @@ let _powerlines_plugin_alloy_core = require("@powerlines/plugin-alloy/core");
12
11
  let _powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
13
12
  let _powerlines_plugin_alloy_typescript = require("@powerlines/plugin-alloy/typescript");
14
13
  let _powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
14
+ let _stryke_path = require("@stryke/path");
15
15
  let _stryke_string_format_snake_case = require("@stryke/string-format/snake-case");
16
16
 
17
17
  //#region src/components/bash-command.tsx
@@ -20,12 +20,15 @@ let _stryke_string_format_snake_case = require("@stryke/string-format/snake-case
20
20
  */
21
21
  function BashCompletionsCommand() {
22
22
  const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
23
+ const bin = (0, _alloy_js_core.computed)(() => (0, _shell_shock_core_plugin_utils.getAppBin)(context));
24
+ const name = (0, _alloy_js_core.computed)(() => (0, _stryke_string_format_snake_case.snakeCase)(bin.value));
23
25
  return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript.TypescriptFile, {
24
26
  get path() {
25
27
  return (0, _stryke_path.joinPaths)(context.entryPath, "completions", "bash", "command.ts");
26
28
  },
27
29
  imports: {
28
- "node:os": ["os"],
30
+ "node:os": "os",
31
+ "node:path": ["join"],
29
32
  "node:fs/promises": ["readFile", "writeFile"]
30
33
  },
31
34
  builtinImports: { "shell-shock:console": [
@@ -51,7 +54,7 @@ function BashCompletionsCommand() {
51
54
  return _powerlines_deepkit_vendor_type.ReflectionKind.string;
52
55
  },
53
56
  get defaultValue() {
54
- return `${(0, _shell_shock_core_plugin_utils.getAppBin)(context)}-completions.bash`;
57
+ return `${bin.value}-completions.bash`;
55
58
  }
56
59
  })];
57
60
  }
@@ -99,7 +102,7 @@ function BashCompletionsCommand() {
99
102
  name: "completions",
100
103
  type: "string",
101
104
  get initializer() {
102
- return _alloy_js_core.code`# bash completion for ${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)}
105
+ return _alloy_js_core.code` \`# bash completion for ${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)}
103
106
 
104
107
  # Define shell completion directives
105
108
  readonly ShellCompDirectiveError=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveError}
@@ -110,21 +113,21 @@ readonly ShellCompDirectiveFilterDirs=${require_helpers_completion_directive_con
110
113
  readonly ShellCompDirectiveKeepOrder=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveKeepOrder}
111
114
 
112
115
  # Function to debug completion
113
- __${(0, _stryke_string_format_snake_case.snakeCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug() {
114
- if [[ -n \${BASH_COMP_DEBUG_FILE:-} ]]; then
115
- echo "$*" >> "\${BASH_COMP_DEBUG_FILE}"
116
+ __${name.value}_debug() {
117
+ if [[ -n \\\${BASH_COMP_DEBUG_FILE:-} ]]; then
118
+ echo "$*" >> "\\\${BASH_COMP_DEBUG_FILE}"
116
119
  fi
117
120
  }
118
121
 
119
122
  # Function to handle completions
120
- __${(0, _stryke_string_format_snake_case.snakeCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_complete() {
123
+ __${name.value}_complete() {
121
124
  local cur prev words cword
122
125
  _get_comp_words_by_ref -n "=:" cur prev words cword
123
126
 
124
127
  local requestComp out directive
125
128
 
126
129
  # Build the command to get completions
127
- requestComp="${require_helpers_complete_command.exec} complete -- \${words[@]:1}"
130
+ requestComp="${require_helpers_complete_command.EXEC_COMMAND} complete -- \\\${words[@]:1}"
128
131
 
129
132
  # Add an empty parameter if the last parameter is complete
130
133
  if [[ -z "$cur" ]]; then
@@ -137,8 +140,8 @@ __${(0, _stryke_string_format_snake_case.snakeCase)((0, _shell_shock_core_plugin
137
140
  # Extract directive if present
138
141
  directive=0
139
142
  if [[ "$out" == *:* ]]; then
140
- directive=\${out##*:}
141
- out=\${out%:*}
143
+ directive=\\\${out##*:}
144
+ out=\\\${out%:*}
142
145
  fi
143
146
 
144
147
  # Process completions based on directive
@@ -186,8 +189,8 @@ __${(0, _stryke_string_format_snake_case.snakeCase)((0, _shell_shock_core_plugin
186
189
  while read -r comp; do
187
190
  if [[ "$comp" == *$tab* ]]; then
188
191
  # Split completion and description
189
- local value=\${comp%%$tab*}
190
- local desc=\${comp#*$tab}
192
+ local value=\\\${comp%%$tab*}
193
+ local desc=\\\${comp#*$tab}
191
194
  completions+=("$value")
192
195
  else
193
196
  completions+=("$comp")
@@ -195,12 +198,12 @@ __${(0, _stryke_string_format_snake_case.snakeCase)((0, _shell_shock_core_plugin
195
198
  done <<< "$out"
196
199
 
197
200
  # Return completions
198
- COMPREPLY=( $(compgen -W "\${completions[*]}" -- "$cur") )
201
+ COMPREPLY=( $(compgen -W "\\\${completions[*]}" -- "$cur") )
199
202
  }
200
203
 
201
204
  # Register completion function
202
- complete -F __${(0, _stryke_string_format_snake_case.snakeCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_complete ${(0, _shell_shock_core_plugin_utils.getAppBin)(context)}
203
- \`); `;
205
+ complete -F __${name.value}_complete ${bin.value}
206
+ \`; `;
204
207
  }
205
208
  }),
206
209
  (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
@@ -230,7 +233,7 @@ complete -F __${(0, _stryke_string_format_snake_case.snakeCase)((0, _shell_shock
230
233
  (0, _alloy_js_core_jsx_runtime.memo)(() => _alloy_js_core.code`try {
231
234
  configFileContent = await readFile(configFilePath, "utf8");
232
235
  } catch (error) {
233
- if (error.code === "ENOENT") {
236
+ if (Error.isError(error) && error.code === "ENOENT") {
234
237
  // If the file doesn't exist, we can create it later when writing the completion script.
235
238
  warn(\`Configuration file \${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\`);
236
239
  } else {
@@ -248,7 +251,7 @@ complete -F __${(0, _stryke_string_format_snake_case.snakeCase)((0, _shell_shock
248
251
  (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
249
252
  condition: _alloy_js_core.code`options.script`,
250
253
  get children() {
251
- return _alloy_js_core.code`const outputPath = options.script === true ? "${(0, _shell_shock_core_plugin_utils.getAppBin)(context)}-completions.bash" : options.script;
254
+ return _alloy_js_core.code`const outputPath = options.script === true ? "${bin.value}-completions.bash" : options.script;
252
255
  await writeFile(outputPath, stripAnsi(completions));
253
256
 
254
257
  success(\`${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)} Bash completion script has been generated at \${colors.bold(outputPath)}.\`);`;
@@ -1,16 +1,16 @@
1
- import { exec } from "../helpers/complete-command.mjs";
1
+ import { EXEC_COMMAND } from "../helpers/complete-command.mjs";
2
2
  import { CompletionDirective } from "../helpers/completion-directive-constants.mjs";
3
3
  import "../helpers/index.mjs";
4
4
  import { createComponent, memo } from "@alloy-js/core/jsx-runtime";
5
5
  import { getAppBin, getAppTitle } from "@shell-shock/core/plugin-utils";
6
- import { joinPaths } from "@stryke/path";
7
- import { code } from "@alloy-js/core";
6
+ import { code, computed } from "@alloy-js/core";
8
7
  import { FunctionDeclaration, IfStatement, InterfaceDeclaration, VarDeclaration } from "@alloy-js/typescript";
9
8
  import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
10
9
  import { Spacing } from "@powerlines/plugin-alloy/core";
11
10
  import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
12
11
  import { InterfaceMember, TypescriptFile } from "@powerlines/plugin-alloy/typescript";
13
12
  import { TSDoc, TSDocDefaultValue, TSDocRemarks } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
13
+ import { joinPaths } from "@stryke/path";
14
14
  import { snakeCase } from "@stryke/string-format/snake-case";
15
15
 
16
16
  //#region src/components/bash-command.tsx
@@ -19,12 +19,15 @@ import { snakeCase } from "@stryke/string-format/snake-case";
19
19
  */
20
20
  function BashCompletionsCommand() {
21
21
  const context = usePowerlines();
22
+ const bin = computed(() => getAppBin(context));
23
+ const name = computed(() => snakeCase(bin.value));
22
24
  return createComponent(TypescriptFile, {
23
25
  get path() {
24
26
  return joinPaths(context.entryPath, "completions", "bash", "command.ts");
25
27
  },
26
28
  imports: {
27
- "node:os": ["os"],
29
+ "node:os": "os",
30
+ "node:path": ["join"],
28
31
  "node:fs/promises": ["readFile", "writeFile"]
29
32
  },
30
33
  builtinImports: { "shell-shock:console": [
@@ -50,7 +53,7 @@ function BashCompletionsCommand() {
50
53
  return ReflectionKind.string;
51
54
  },
52
55
  get defaultValue() {
53
- return `${getAppBin(context)}-completions.bash`;
56
+ return `${bin.value}-completions.bash`;
54
57
  }
55
58
  })];
56
59
  }
@@ -98,7 +101,7 @@ function BashCompletionsCommand() {
98
101
  name: "completions",
99
102
  type: "string",
100
103
  get initializer() {
101
- return code`# bash completion for ${getAppTitle(context)}
104
+ return code` \`# bash completion for ${getAppTitle(context)}
102
105
 
103
106
  # Define shell completion directives
104
107
  readonly ShellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}
@@ -109,21 +112,21 @@ readonly ShellCompDirectiveFilterDirs=${CompletionDirective.CompletionDirectiveF
109
112
  readonly ShellCompDirectiveKeepOrder=${CompletionDirective.CompletionDirectiveKeepOrder}
110
113
 
111
114
  # Function to debug completion
112
- __${snakeCase(getAppBin(context))}_debug() {
113
- if [[ -n \${BASH_COMP_DEBUG_FILE:-} ]]; then
114
- echo "$*" >> "\${BASH_COMP_DEBUG_FILE}"
115
+ __${name.value}_debug() {
116
+ if [[ -n \\\${BASH_COMP_DEBUG_FILE:-} ]]; then
117
+ echo "$*" >> "\\\${BASH_COMP_DEBUG_FILE}"
115
118
  fi
116
119
  }
117
120
 
118
121
  # Function to handle completions
119
- __${snakeCase(getAppBin(context))}_complete() {
122
+ __${name.value}_complete() {
120
123
  local cur prev words cword
121
124
  _get_comp_words_by_ref -n "=:" cur prev words cword
122
125
 
123
126
  local requestComp out directive
124
127
 
125
128
  # Build the command to get completions
126
- requestComp="${exec} complete -- \${words[@]:1}"
129
+ requestComp="${EXEC_COMMAND} complete -- \\\${words[@]:1}"
127
130
 
128
131
  # Add an empty parameter if the last parameter is complete
129
132
  if [[ -z "$cur" ]]; then
@@ -136,8 +139,8 @@ __${snakeCase(getAppBin(context))}_complete() {
136
139
  # Extract directive if present
137
140
  directive=0
138
141
  if [[ "$out" == *:* ]]; then
139
- directive=\${out##*:}
140
- out=\${out%:*}
142
+ directive=\\\${out##*:}
143
+ out=\\\${out%:*}
141
144
  fi
142
145
 
143
146
  # Process completions based on directive
@@ -185,8 +188,8 @@ __${snakeCase(getAppBin(context))}_complete() {
185
188
  while read -r comp; do
186
189
  if [[ "$comp" == *$tab* ]]; then
187
190
  # Split completion and description
188
- local value=\${comp%%$tab*}
189
- local desc=\${comp#*$tab}
191
+ local value=\\\${comp%%$tab*}
192
+ local desc=\\\${comp#*$tab}
190
193
  completions+=("$value")
191
194
  else
192
195
  completions+=("$comp")
@@ -194,12 +197,12 @@ __${snakeCase(getAppBin(context))}_complete() {
194
197
  done <<< "$out"
195
198
 
196
199
  # Return completions
197
- COMPREPLY=( $(compgen -W "\${completions[*]}" -- "$cur") )
200
+ COMPREPLY=( $(compgen -W "\\\${completions[*]}" -- "$cur") )
198
201
  }
199
202
 
200
203
  # Register completion function
201
- complete -F __${snakeCase(getAppBin(context))}_complete ${getAppBin(context)}
202
- \`); `;
204
+ complete -F __${name.value}_complete ${bin.value}
205
+ \`; `;
203
206
  }
204
207
  }),
205
208
  createComponent(Spacing, {}),
@@ -229,7 +232,7 @@ complete -F __${snakeCase(getAppBin(context))}_complete ${getAppBin(context)}
229
232
  memo(() => code`try {
230
233
  configFileContent = await readFile(configFilePath, "utf8");
231
234
  } catch (error) {
232
- if (error.code === "ENOENT") {
235
+ if (Error.isError(error) && error.code === "ENOENT") {
233
236
  // If the file doesn't exist, we can create it later when writing the completion script.
234
237
  warn(\`Configuration file \${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\`);
235
238
  } else {
@@ -247,7 +250,7 @@ complete -F __${snakeCase(getAppBin(context))}_complete ${getAppBin(context)}
247
250
  createComponent(IfStatement, {
248
251
  condition: code`options.script`,
249
252
  get children() {
250
- return code`const outputPath = options.script === true ? "${getAppBin(context)}-completions.bash" : options.script;
253
+ return code`const outputPath = options.script === true ? "${bin.value}-completions.bash" : options.script;
251
254
  await writeFile(outputPath, stripAnsi(completions));
252
255
 
253
256
  success(\`${getAppTitle(context)} Bash completion script has been generated at \${colors.bold(outputPath)}.\`);`;
@@ -1 +1 @@
1
- {"version":3,"file":"bash-command.mjs","names":[],"sources":["../../src/components/bash-command.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 {\n InterfaceMember,\n TypescriptFile\n} from \"@powerlines/plugin-alloy/typescript\";\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 { snakeCase } from \"@stryke/string-format/snake-case\";\nimport { CompletionDirective } from \"../helpers\";\nimport { exec } from \"../helpers/complete-command\";\nimport type { CompletionsPluginContext } from \"../types/plugin\";\n\n/**\n * The Bash Completions commands' handler wrapper for the Shell Shock project.\n */\nexport function BashCompletionsCommand() {\n const context = usePowerlines<CompletionsPluginContext>();\n\n return (\n <TypescriptFile\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=\"Handler logic for the \\`completions bash\\` 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`# bash completion for ${getAppTitle(context)}\n\n# Define shell completion directives\nreadonly ShellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}\nreadonly ShellCompDirectiveNoSpace=${\n CompletionDirective.CompletionDirectiveNoSpace\n }\nreadonly ShellCompDirectiveNoFileComp=${\n CompletionDirective.CompletionDirectiveNoFileComp\n }\nreadonly ShellCompDirectiveFilterFileExt=${\n CompletionDirective.CompletionDirectiveFilterFileExt\n }\nreadonly ShellCompDirectiveFilterDirs=${\n CompletionDirective.CompletionDirectiveFilterDirs\n }\nreadonly ShellCompDirectiveKeepOrder=${\n CompletionDirective.CompletionDirectiveKeepOrder\n }\n\n# Function to debug completion\n__${snakeCase(getAppBin(context))}_debug() {\n if [[ -n \\${BASH_COMP_DEBUG_FILE:-} ]]; then\n echo \"$*\" >> \"\\${BASH_COMP_DEBUG_FILE}\"\n fi\n}\n\n# Function to handle completions\n__${snakeCase(getAppBin(context))}_complete() {\n local cur prev words cword\n _get_comp_words_by_ref -n \"=:\" cur prev words cword\n\n local requestComp out directive\n\n # Build the command to get completions\n requestComp=\"${exec} complete -- \\${words[@]:1}\"\n\n # Add an empty parameter if the last parameter is complete\n if [[ -z \"$cur\" ]]; then\n requestComp=\"$requestComp ''\"\n fi\n\n # Get completions from the program\n out=$(eval \"$requestComp\" 2>/dev/null)\n\n # Extract directive if present\n directive=0\n if [[ \"$out\" == *:* ]]; then\n directive=\\${out##*:}\n out=\\${out%:*}\n fi\n\n # Process completions based on directive\n if [[ $((directive & $ShellCompDirectiveError)) -ne 0 ]]; then\n # Error, no completion\n return\n fi\n\n # Apply directives\n if [[ $((directive & $ShellCompDirectiveNoSpace)) -ne 0 ]]; then\n compopt -o nospace\n fi\n if [[ $((directive & $ShellCompDirectiveKeepOrder)) -ne 0 ]]; then\n compopt -o nosort\n fi\n if [[ $((directive & $ShellCompDirectiveNoFileComp)) -ne 0 ]]; then\n compopt +o default\n fi\n\n # Handle file extension filtering\n if [[ $((directive & $ShellCompDirectiveFilterFileExt)) -ne 0 ]]; then\n local filter=\"\"\n for ext in $out; do\n filter=\"$filter|$ext\"\n done\n filter=\"\\\\.($filter)\"\n compopt -o filenames\n COMPREPLY=( $(compgen -f -X \"!$filter\" -- \"$cur\") )\n return\n fi\n\n # Handle directory filtering\n if [[ $((directive & $ShellCompDirectiveFilterDirs)) -ne 0 ]]; then\n compopt -o dirnames\n COMPREPLY=( $(compgen -d -- \"$cur\") )\n return\n fi\n\n # Process completions\n local IFS=$'\\\\n'\n local tab=$(printf '\\\\t')\n\n # Parse completions with descriptions\n local completions=()\n while read -r comp; do\n if [[ \"$comp\" == *$tab* ]]; then\n # Split completion and description\n local value=\\${comp%%$tab*}\n local desc=\\${comp#*$tab}\n completions+=(\"$value\")\n else\n completions+=(\"$comp\")\n fi\n done <<< \"$out\"\n\n # Return completions\n COMPREPLY=( $(compgen -W \"\\${completions[*]}\" -- \"$cur\") )\n}\n\n# Register completion function\ncomplete -F __${snakeCase(getAppBin(context))}_complete ${getAppBin(context)}\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 </TypescriptFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoCA,SAAS,yBAAwB;CACjC,MAAQ,UAAU,eAAwC;AAC1D,QAAS,gBAAkB,gBAAa;EACxC,IAAQ,OAAC;AACH,UAAG,UAAA,QAAsB,WAAS,eAAQ,QAAA,aAAA;;EAEhD,SAAa;;GAEX,oBAAA,CAAA,YAAA,YAAA;GACC;EACD,gBAAA,EACI,uBAAU;GAAA;GAAwB;GAAC;GAAA;GAAA;GAAA,EACvC;;AAEA,UAAO;IAAA,gBAAA,OAAA,EACJ,SAAA,6CACC,CAAA;IAAI,gBAAY,sBAAoB;KACpC,UAAS;KACP,MAAM;KACN,IAAC,WAAQ;AACV,aAAA;OAAA,gBAAA,OAAA;QACD,SAAe;QACZ,IAAM,WAAM;AACV,gBAAO,CAAA,gBAAA,cAAA,EACP,UAAU,sEACV,CAAA,EAAO,gBAAC,mBAAA;UACH,IAAA,OAAA;AACL,kBAAS,eAAA;;UAEZ,IAAA,eAAA;AACK,kBAAS,GAAA,UAAgB,QAAK,CAAA;;UAE5B,CAAA,CAAA;;QAEJ,CAAA;OAAA,gBAAA,iBAAA;QACC,MAAM;QACN,UAAA;QACD,MAAA;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AAA,gBAA6B,aAAG;WAC1D,WAAK,IAAA;WACN,UAAW,IAAA;WACZ,CAAA;UAAO,gBAAE,SAAA,EAAA,CAAA;UAAA,gBAAA,gBAAA;WACT,OAAA;WACC,MAAA;WACI,MAAE;WACF,aAAQ,IAAA;WACZ,CAAA;UAAA,gBAAsB,SAAA,EAAA,CAAA;UAAA,WAAA,IAAA;;;;;;;;;;;;;;;;;;;QAgBxB,WAAY,IAAA;QACZ,IAAA,WAAW;AACZ,gBAAS,IAAA,iDAAA,UAAA,QAAA,CAAA;;;sBAGF,YAAU,QAAY,CAAA;;QAE5B,CAAA;OAAA,gBAAY,SAAmB,EAAE,CAAC;OAAA,gBAAgB,aAAgB;QAClE,WAAW,IAAA;QACZ,UAAS,IAAA;;;QAGR,CAAA;OAAA;;KAEH,CAAC;IAAC;;EAEN,CAAC"}
1
+ {"version":3,"file":"bash-command.mjs","names":[],"sources":["../../src/components/bash-command.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, computed } 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 {\n InterfaceMember,\n TypescriptFile\n} from \"@powerlines/plugin-alloy/typescript\";\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 { snakeCase } from \"@stryke/string-format/snake-case\";\nimport { CompletionDirective } from \"../helpers\";\nimport { EXEC_COMMAND } from \"../helpers/complete-command\";\nimport type { CompletionsPluginContext } from \"../types/plugin\";\n\n/**\n * The Bash Completions commands' handler wrapper for the Shell Shock project.\n */\nexport function BashCompletionsCommand() {\n const context = usePowerlines<CompletionsPluginContext>();\n\n const bin = computed(() => getAppBin(context));\n const name = computed(() => snakeCase(bin.value));\n\n return (\n <TypescriptFile\n path={joinPaths(context.entryPath, \"completions\", \"bash\", \"command.ts\")}\n imports={{\n \"node:os\": \"os\",\n \"node:path\": [\"join\"],\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={`${bin.value}-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=\"Handler logic for the \\`completions bash\\` 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` \\`# bash completion for ${getAppTitle(context)}\n\n# Define shell completion directives\nreadonly ShellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}\nreadonly ShellCompDirectiveNoSpace=${\n CompletionDirective.CompletionDirectiveNoSpace\n }\nreadonly ShellCompDirectiveNoFileComp=${\n CompletionDirective.CompletionDirectiveNoFileComp\n }\nreadonly ShellCompDirectiveFilterFileExt=${\n CompletionDirective.CompletionDirectiveFilterFileExt\n }\nreadonly ShellCompDirectiveFilterDirs=${\n CompletionDirective.CompletionDirectiveFilterDirs\n }\nreadonly ShellCompDirectiveKeepOrder=${\n CompletionDirective.CompletionDirectiveKeepOrder\n }\n\n# Function to debug completion\n__${name.value}_debug() {\n if [[ -n \\\\\\${BASH_COMP_DEBUG_FILE:-} ]]; then\n echo \"$*\" >> \"\\\\\\${BASH_COMP_DEBUG_FILE}\"\n fi\n}\n\n# Function to handle completions\n__${name.value}_complete() {\n local cur prev words cword\n _get_comp_words_by_ref -n \"=:\" cur prev words cword\n\n local requestComp out directive\n\n # Build the command to get completions\n requestComp=\"${EXEC_COMMAND} complete -- \\\\\\${words[@]:1}\"\n\n # Add an empty parameter if the last parameter is complete\n if [[ -z \"$cur\" ]]; then\n requestComp=\"$requestComp ''\"\n fi\n\n # Get completions from the program\n out=$(eval \"$requestComp\" 2>/dev/null)\n\n # Extract directive if present\n directive=0\n if [[ \"$out\" == *:* ]]; then\n directive=\\\\\\${out##*:}\n out=\\\\\\${out%:*}\n fi\n\n # Process completions based on directive\n if [[ $((directive & $ShellCompDirectiveError)) -ne 0 ]]; then\n # Error, no completion\n return\n fi\n\n # Apply directives\n if [[ $((directive & $ShellCompDirectiveNoSpace)) -ne 0 ]]; then\n compopt -o nospace\n fi\n if [[ $((directive & $ShellCompDirectiveKeepOrder)) -ne 0 ]]; then\n compopt -o nosort\n fi\n if [[ $((directive & $ShellCompDirectiveNoFileComp)) -ne 0 ]]; then\n compopt +o default\n fi\n\n # Handle file extension filtering\n if [[ $((directive & $ShellCompDirectiveFilterFileExt)) -ne 0 ]]; then\n local filter=\"\"\n for ext in $out; do\n filter=\"$filter|$ext\"\n done\n filter=\"\\\\.($filter)\"\n compopt -o filenames\n COMPREPLY=( $(compgen -f -X \"!$filter\" -- \"$cur\") )\n return\n fi\n\n # Handle directory filtering\n if [[ $((directive & $ShellCompDirectiveFilterDirs)) -ne 0 ]]; then\n compopt -o dirnames\n COMPREPLY=( $(compgen -d -- \"$cur\") )\n return\n fi\n\n # Process completions\n local IFS=$'\\\\n'\n local tab=$(printf '\\\\t')\n\n # Parse completions with descriptions\n local completions=()\n while read -r comp; do\n if [[ \"$comp\" == *$tab* ]]; then\n # Split completion and description\n local value=\\\\\\${comp%%$tab*}\n local desc=\\\\\\${comp#*$tab}\n completions+=(\"$value\")\n else\n completions+=(\"$comp\")\n fi\n done <<< \"$out\"\n\n # Return completions\n COMPREPLY=( $(compgen -W \"\\\\\\${completions[*]}\" -- \"$cur\") )\n}\n\n# Register completion function\ncomplete -F __${name.value}_complete ${bin.value}\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.isError(error) && 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 ? \"${\n bin.value\n }-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 </TypescriptFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoCA,SAAS,yBAAwB;CACjC,MAAQ,UAAU,eAAwC;CAC1D,MAAQ,MAAC,eAAmB,UAAW,QAAC,CAAA;CACxC,MAAQ,OAAC,eAAmB,UAAO,IAAO,MAAO,CAAA;AACjD,QAAS,gBAAA,gBAA+B;EACxC,IAAQ,OAAC;AACH,UAAO,UAAC,QAAA,WAA2B,eAAe,QAAO,aAAA;;EAE7D,SAAA;GACI,WAAM;GACV,aAAA,CAAA,OAAA;GACI,oBAAU,CAAA,YAAuB,YAAE;GACvC;oBAEA,uBAA2B;GAAA;GAAU;GAAS;GAAA;GAAA;GAAA,EAC9C;;AAEA,UAAO;IAAA,gBAAA,OAAA,EACJ,SAAA,6CACC,CAAA;IAAI,gBAAY,sBAAoB;KACpC,UAAS;KACP,MAAM;KACN,IAAC,WAAc;AACd,aAAQ;OAAA,gBAAa,OAAY;QACnC,SAAA;QACD,IAAA,WAAgB;AACR,gBAAO,CAAA,gBAAU,cAAA,EACpB,UAAO,sE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