@shell-shock/plugin-completions 0.4.16 → 0.4.18

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 (56) hide show
  1. package/dist/components/bash-config-command.cjs +120 -6
  2. package/dist/components/bash-config-command.mjs +119 -6
  3. package/dist/components/bash-config-command.mjs.map +1 -1
  4. package/dist/components/bash-script-command.cjs +105 -5
  5. package/dist/components/bash-script-command.mjs +104 -5
  6. package/dist/components/bash-script-command.mjs.map +1 -1
  7. package/dist/components/bash-shared.cjs +77 -13
  8. package/dist/components/bash-shared.mjs +76 -13
  9. package/dist/components/bash-shared.mjs.map +1 -1
  10. package/dist/components/fish-config-command.cjs +120 -6
  11. package/dist/components/fish-config-command.mjs +119 -6
  12. package/dist/components/fish-config-command.mjs.map +1 -1
  13. package/dist/components/fish-script-command.cjs +104 -4
  14. package/dist/components/fish-script-command.mjs +103 -4
  15. package/dist/components/fish-script-command.mjs.map +1 -1
  16. package/dist/components/fish-shared.cjs +141 -77
  17. package/dist/components/fish-shared.mjs +140 -77
  18. package/dist/components/fish-shared.mjs.map +1 -1
  19. package/dist/components/index.cjs +26 -1
  20. package/dist/components/index.mjs +14 -1
  21. package/dist/components/powershell-config-command.cjs +116 -6
  22. package/dist/components/powershell-config-command.mjs +115 -6
  23. package/dist/components/powershell-config-command.mjs.map +1 -1
  24. package/dist/components/powershell-script-command.cjs +104 -4
  25. package/dist/components/powershell-script-command.mjs +103 -4
  26. package/dist/components/powershell-script-command.mjs.map +1 -1
  27. package/dist/components/powershell-shared.cjs +101 -37
  28. package/dist/components/powershell-shared.mjs +100 -37
  29. package/dist/components/powershell-shared.mjs.map +1 -1
  30. package/dist/components/zsh-config-command.cjs +120 -6
  31. package/dist/components/zsh-config-command.mjs +119 -6
  32. package/dist/components/zsh-config-command.mjs.map +1 -1
  33. package/dist/components/zsh-script-command.cjs +108 -6
  34. package/dist/components/zsh-script-command.mjs +107 -6
  35. package/dist/components/zsh-script-command.mjs.map +1 -1
  36. package/dist/components/zsh-shared.cjs +106 -42
  37. package/dist/components/zsh-shared.mjs +105 -42
  38. package/dist/components/zsh-shared.mjs.map +1 -1
  39. package/dist/helpers/complete-command.cjs +10 -1
  40. package/dist/helpers/complete-command.mjs +8 -1
  41. package/dist/helpers/complete-command.mjs.map +1 -1
  42. package/dist/helpers/completion-directive-constants.cjs +16 -1
  43. package/dist/helpers/completion-directive-constants.mjs +14 -1
  44. package/dist/helpers/completion-directive-constants.mjs.map +1 -1
  45. package/dist/helpers/index.cjs +6 -1
  46. package/dist/helpers/index.mjs +4 -1
  47. package/dist/index.cjs +303 -1
  48. package/dist/index.mjs +301 -1
  49. package/dist/index.mjs.map +1 -1
  50. package/dist/types/index.cjs +4 -1
  51. package/dist/types/index.mjs +3 -1
  52. package/dist/types/plugin.mjs +1 -1
  53. package/dist/types/shell-type.cjs +12 -1
  54. package/dist/types/shell-type.mjs +10 -1
  55. package/dist/types/shell-type.mjs.map +1 -1
  56. package/package.json +10 -10
@@ -1,17 +1,65 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../helpers/complete-command.cjs`),t=require(`../helpers/completion-directive-constants.cjs`);require(`../helpers/index.cjs`);let n=require(`@alloy-js/core/jsx-runtime`),r=require(`@shell-shock/core/plugin-utils`),i=require(`@alloy-js/core`),a=require(`@alloy-js/typescript`),o=require(`@powerlines/plugin-alloy/core`),s=require(`@powerlines/plugin-alloy/core/contexts/context`),c=require(`@powerlines/plugin-alloy/typescript`),l=require(`@stryke/path`),u=require(`@stryke/string-format/camel-case`);function d(){let d=(0,s.usePowerlines)(),f=(0,i.computed)(()=>(0,r.getAppBin)(d)),p=(0,i.computed)(()=>(0,u.camelCase)(f.value));return(0,n.createComponent)(c.TypescriptFile,{get path(){return(0,l.joinPaths)(d.entryPath,`completions`,`powershell`,`shared.ts`)},builtinImports:{console:[`white`,`green`,`red`,`bold`,`cyan`,`gray`,`magenta`,`magentaBright`,`greenBright`,`redBright`,`cyanBright`,`dim`]},get children(){return[(0,n.createComponent)(o.Spacing,{}),(0,n.createComponent)(a.VarDeclaration,{const:!0,export:!0,name:`SHELL_COMPLETIONS`,get initializer(){return i.code` \`# powershell completion for ${(0,r.getAppTitle)(d)}
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_helpers_complete_command = require('../helpers/complete-command.cjs');
3
+ const require_helpers_completion_directive_constants = require('../helpers/completion-directive-constants.cjs');
4
+ require('../helpers/index.cjs');
5
+ let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
6
+ let _shell_shock_core_plugin_utils = require("@shell-shock/core/plugin-utils");
7
+ let _alloy_js_core = require("@alloy-js/core");
8
+ let _alloy_js_typescript = require("@alloy-js/typescript");
9
+ let _powerlines_plugin_alloy_core = require("@powerlines/plugin-alloy/core");
10
+ let _powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
11
+ let _powerlines_plugin_alloy_typescript = require("@powerlines/plugin-alloy/typescript");
12
+ let _stryke_path = require("@stryke/path");
13
+ let _stryke_string_format_camel_case = require("@stryke/string-format/camel-case");
14
+
15
+ //#region src/components/powershell-shared.tsx
16
+ /**
17
+ * The PowerShell Completions generation for the Shell Shock project.
18
+ */
19
+ function PowerShellCompletionsShared() {
20
+ const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
21
+ const bin = (0, _alloy_js_core.computed)(() => (0, _shell_shock_core_plugin_utils.getAppBin)(context));
22
+ const name = (0, _alloy_js_core.computed)(() => (0, _stryke_string_format_camel_case.camelCase)(bin.value));
23
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript.TypescriptFile, {
24
+ get path() {
25
+ return (0, _stryke_path.joinPaths)(context.entryPath, "completions", "powershell", "shared.ts");
26
+ },
27
+ builtinImports: { console: [
28
+ "white",
29
+ "green",
30
+ "red",
31
+ "bold",
32
+ "cyan",
33
+ "gray",
34
+ "magenta",
35
+ "magentaBright",
36
+ "greenBright",
37
+ "redBright",
38
+ "cyanBright",
39
+ "dim"
40
+ ] },
41
+ get children() {
42
+ return [
43
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
44
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
45
+ "const": true,
46
+ "export": true,
47
+ name: "SHELL_COMPLETIONS",
48
+ get initializer() {
49
+ return _alloy_js_core.code` \`# powershell completion for ${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)}
2
50
 
3
51
  [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
4
- function __${p.value}_debug {
52
+ function __${name.value}_debug {
5
53
  if ($env:BASH_COMP_DEBUG_FILE) {
6
54
  "$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
7
55
  }
8
56
  }
9
57
 
10
- filter __${p.value}_escapeStringWithSpecialChars {
58
+ filter __${name.value}_escapeStringWithSpecialChars {
11
59
  $_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\\\`$&'
12
60
  }
13
61
 
14
- [scriptblock]$__${p.value}CompleterBlock = {
62
+ [scriptblock]$__${name.value}CompleterBlock = {
15
63
  param(
16
64
  $WordToComplete,
17
65
  $CommandAst,
@@ -22,9 +70,9 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
22
70
  $Command = $CommandAst.CommandElements
23
71
  $Command = "$Command"
24
72
 
25
- __${p.value}_debug ""
26
- __${p.value}_debug "========= starting completion logic =========="
27
- __${p.value}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
73
+ __${name.value}_debug ""
74
+ __${name.value}_debug "========= starting completion logic =========="
75
+ __${name.value}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
28
76
 
29
77
  # The user could have moved the cursor backwards on the command-line.
30
78
  # We need to trigger completion from the $CursorPosition location, so we need
@@ -34,24 +82,24 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
34
82
  if ($Command.Length -gt $CursorPosition) {
35
83
  $Command = $Command.Substring(0, $CursorPosition)
36
84
  }
37
- __${p.value}_debug "Truncated command: $Command"
85
+ __${name.value}_debug "Truncated command: $Command"
38
86
 
39
- $ShellCompDirectiveError=${t.CompletionDirective.CompletionDirectiveError}
40
- $ShellCompDirectiveNoSpace=${t.CompletionDirective.CompletionDirectiveNoSpace}
41
- $ShellCompDirectiveNoFileComp=${t.CompletionDirective.CompletionDirectiveNoFileComp}
42
- $ShellCompDirectiveFilterFileExt=${t.CompletionDirective.CompletionDirectiveFilterFileExt}
43
- $ShellCompDirectiveFilterDirs=${t.CompletionDirective.CompletionDirectiveFilterDirs}
44
- $ShellCompDirectiveKeepOrder=${t.CompletionDirective.CompletionDirectiveKeepOrder}
87
+ $ShellCompDirectiveError=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveError}
88
+ $ShellCompDirectiveNoSpace=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveNoSpace}
89
+ $ShellCompDirectiveNoFileComp=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveNoFileComp}
90
+ $ShellCompDirectiveFilterFileExt=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveFilterFileExt}
91
+ $ShellCompDirectiveFilterDirs=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveFilterDirs}
92
+ $ShellCompDirectiveKeepOrder=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveKeepOrder}
45
93
 
46
94
  # Prepare the command to request completions for the program.
47
95
  # Split the command at the first space to separate the program and arguments.
48
96
  $Program, $Arguments = $Command.Split(" ", 2)
49
97
 
50
98
  $QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
51
- __${p.value}_debug "QuotedArgs: $QuotedArgs"
99
+ __${name.value}_debug "QuotedArgs: $QuotedArgs"
52
100
 
53
- $RequestComp = "& ${e.EXEC_COMMAND} complete '--' $QuotedArgs"
54
- __${p.value}_debug "RequestComp: $RequestComp"
101
+ $RequestComp = "& ${require_helpers_complete_command.EXEC_COMMAND} complete '--' $QuotedArgs"
102
+ __${name.value}_debug "RequestComp: $RequestComp"
55
103
 
56
104
  # we cannot use $WordToComplete because it
57
105
  # has the wrong values if the cursor was moved
@@ -59,13 +107,13 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
59
107
  if ($WordToComplete -ne "" ) {
60
108
  $WordToComplete = $Arguments.Split(" ")[-1]
61
109
  }
62
- __${p.value}_debug "New WordToComplete: $WordToComplete"
110
+ __${name.value}_debug "New WordToComplete: $WordToComplete"
63
111
 
64
112
 
65
113
  # Check for flag with equal sign
66
114
  $IsEqualFlag = ($WordToComplete -Like "--*=*" )
67
115
  if ( $IsEqualFlag ) {
68
- __${p.value}_debug "Completing equal sign flag"
116
+ __${name.value}_debug "Completing equal sign flag"
69
117
  # Remove the flag part
70
118
  $Flag, $WordToComplete = $WordToComplete.Split("=", 2)
71
119
  }
@@ -73,7 +121,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
73
121
  if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
74
122
  # If the last parameter is complete (there is a space following it)
75
123
  # We add an extra empty parameter so we can indicate this to the go method.
76
- __${p.value}_debug "Adding extra empty parameter"
124
+ __${name.value}_debug "Adding extra empty parameter"
77
125
  # PowerShell 7.2+ changed the way how the arguments are passed to executables,
78
126
  # so for pre-7.2 or when Legacy argument passing is enabled we need to use
79
127
  if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
@@ -86,7 +134,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
86
134
  }
87
135
  }
88
136
 
89
- __${p.value}_debug "Calling $RequestComp"
137
+ __${name.value}_debug "Calling $RequestComp"
90
138
  # First disable ActiveHelp which is not supported for Powershell
91
139
  $env:ActiveHelp = 0
92
140
 
@@ -100,14 +148,14 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
100
148
  # There is no directive specified
101
149
  $Directive = 0
102
150
  }
103
- __${p.value}_debug "The completion directive is: $Directive"
151
+ __${name.value}_debug "The completion directive is: $Directive"
104
152
 
105
153
  # remove directive (last element) from out
106
154
  $Out = $Out | Where-Object { $_ -ne $Out[-1] }
107
- __${p.value}_debug "The completions are: $Out"
155
+ __${name.value}_debug "The completions are: $Out"
108
156
  if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
109
157
  # Error code. No completion.
110
- __${p.value}_debug "Received error from custom completion go code"
158
+ __${name.value}_debug "Received error from custom completion go code"
111
159
  return
112
160
  }
113
161
 
@@ -115,7 +163,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
115
163
  [Array]$Values = $Out | ForEach-Object {
116
164
  # Split the output in name and description
117
165
  $Name, $Description = $_.Split("\\\`t", 2)
118
- __${p.value}_debug "Name: $Name Description: $Description"
166
+ __${name.value}_debug "Name: $Name Description: $Description"
119
167
 
120
168
  # Look for the longest completion so that we can format things nicely
121
169
  if ($Longest -lt $Name.Length) {
@@ -134,13 +182,13 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
134
182
  $Space = " "
135
183
  if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
136
184
  # remove the space here
137
- __${p.value}_debug "ShellCompDirectiveNoSpace is called"
185
+ __${name.value}_debug "ShellCompDirectiveNoSpace is called"
138
186
  $Space = ""
139
187
  }
140
188
 
141
189
  if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
142
190
  (($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
143
- __${p.value}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
191
+ __${name.value}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
144
192
 
145
193
  # return here to prevent the completion of the extensions
146
194
  return
@@ -152,7 +200,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
152
200
 
153
201
  # Join the flag back if we have an equal sign flag
154
202
  if ( $IsEqualFlag ) {
155
- __${p.value}_debug "Join the equal sign flag back to the completion value"
203
+ __${name.value}_debug "Join the equal sign flag back to the completion value"
156
204
  $_.Name = $Flag + "=" + $_.Name
157
205
  }
158
206
  }
@@ -163,7 +211,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
163
211
  }
164
212
 
165
213
  if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
166
- __${p.value}_debug "ShellCompDirectiveNoFileComp is called"
214
+ __${name.value}_debug "ShellCompDirectiveNoFileComp is called"
167
215
 
168
216
  if ($Values.Length -eq 0) {
169
217
  # Just print an empty string here so the
@@ -177,7 +225,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
177
225
 
178
226
  # Get the current mode
179
227
  $Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
180
- __${p.value}_debug "Mode: $Mode"
228
+ __${name.value}_debug "Mode: $Mode"
181
229
 
182
230
  $Values | ForEach-Object {
183
231
 
@@ -202,10 +250,10 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
202
250
  "Complete" {
203
251
 
204
252
  if ($Values.Length -eq 1) {
205
- __${p.value}_debug "Only one completion left"
253
+ __${name.value}_debug "Only one completion left"
206
254
 
207
255
  # insert space after value
208
- [System.Management.Automation.CompletionResult]::new($($comp.Name | __${p.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
256
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${name.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
209
257
 
210
258
  } else {
211
259
  # Add the proper number of spaces to align the descriptions
@@ -229,7 +277,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
229
277
  # insert space after value
230
278
  # MenuComplete will automatically show the ToolTip of
231
279
  # the highlighted value at the bottom of the suggestions.
232
- [System.Management.Automation.CompletionResult]::new($($comp.Name | __${p.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
280
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${name.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
233
281
  }
234
282
 
235
283
  # TabCompleteNext and in case we get something unknown
@@ -237,14 +285,22 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
237
285
  # Like MenuComplete but we don't want to add a space here because
238
286
  # the user need to press space anyway to get the completion.
239
287
  # Description will not be shown because that's not possible with TabCompleteNext
240
- [System.Management.Automation.CompletionResult]::new($($comp.Name | __${p.value}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
288
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${name.value}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
241
289
  }
242
290
  }
243
291
  }
244
292
  }
245
293
 
246
- Register-ArgumentCompleter -CommandName '${f.value}' -ScriptBlock $__${p.value}CompleterBlock
247
- \`; `}}),(0,n.createComponent)(o.Spacing,{}),(0,n.createComponent)(a.VarDeclaration,{export:!0,const:!0,name:`SHELL_COMPLETIONS_DISPLAY`,initializer:i.code` SHELL_COMPLETIONS.split("\\n").map(line => {
294
+ Register-ArgumentCompleter -CommandName '${bin.value}' -ScriptBlock $__${name.value}CompleterBlock
295
+ \`; `;
296
+ }
297
+ }),
298
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
299
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
300
+ "export": true,
301
+ "const": true,
302
+ name: "SHELL_COMPLETIONS_DISPLAY",
303
+ initializer: _alloy_js_core.code` SHELL_COMPLETIONS.split("\\n").map(line => {
248
304
  if (!line.trim()) {
249
305
  return "";
250
306
  }
@@ -265,4 +321,12 @@ Register-ArgumentCompleter -CommandName '${f.value}' -ScriptBlock $__${p.value}C
265
321
  .replaceAll(/\\$?__\\w/g, bold(magentaBright("$&")))
266
322
  .replaceAll(/(?<=\\s)(-\\w|--\\w[\\w-]*)(?=\\s|$)/g, bold(magenta("$&")));
267
323
 
268
- }).join("\\n"); `})]}})}exports.PowerShellCompletionsShared=d;
324
+ }).join("\\n"); `
325
+ })
326
+ ];
327
+ }
328
+ });
329
+ }
330
+
331
+ //#endregion
332
+ exports.PowerShellCompletionsShared = PowerShellCompletionsShared;
@@ -1,17 +1,64 @@
1
- import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{CompletionDirective as t}from"../helpers/completion-directive-constants.mjs";import"../helpers/index.mjs";import{createComponent as n}from"@alloy-js/core/jsx-runtime";import{getAppBin as r,getAppTitle as i}from"@shell-shock/core/plugin-utils";import{code as a,computed as o}from"@alloy-js/core";import{VarDeclaration as s}from"@alloy-js/typescript";import{Spacing as c}from"@powerlines/plugin-alloy/core";import{usePowerlines as l}from"@powerlines/plugin-alloy/core/contexts/context";import{TypescriptFile as u}from"@powerlines/plugin-alloy/typescript";import{joinPaths as d}from"@stryke/path";import{camelCase as f}from"@stryke/string-format/camel-case";function p(){let p=l(),m=o(()=>r(p)),h=o(()=>f(m.value));return n(u,{get path(){return d(p.entryPath,`completions`,`powershell`,`shared.ts`)},builtinImports:{console:[`white`,`green`,`red`,`bold`,`cyan`,`gray`,`magenta`,`magentaBright`,`greenBright`,`redBright`,`cyanBright`,`dim`]},get children(){return[n(c,{}),n(s,{const:!0,export:!0,name:`SHELL_COMPLETIONS`,get initializer(){return a` \`# powershell completion for ${i(p)}
1
+ import { EXEC_COMMAND } from "../helpers/complete-command.mjs";
2
+ import { CompletionDirective } from "../helpers/completion-directive-constants.mjs";
3
+ import "../helpers/index.mjs";
4
+ import { createComponent } from "@alloy-js/core/jsx-runtime";
5
+ import { getAppBin, getAppTitle } from "@shell-shock/core/plugin-utils";
6
+ import { code, computed } from "@alloy-js/core";
7
+ import { VarDeclaration } from "@alloy-js/typescript";
8
+ import { Spacing } from "@powerlines/plugin-alloy/core";
9
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
10
+ import { TypescriptFile } from "@powerlines/plugin-alloy/typescript";
11
+ import { joinPaths } from "@stryke/path";
12
+ import { camelCase } from "@stryke/string-format/camel-case";
13
+
14
+ //#region src/components/powershell-shared.tsx
15
+ /**
16
+ * The PowerShell Completions generation for the Shell Shock project.
17
+ */
18
+ function PowerShellCompletionsShared() {
19
+ const context = usePowerlines();
20
+ const bin = computed(() => getAppBin(context));
21
+ const name = computed(() => camelCase(bin.value));
22
+ return createComponent(TypescriptFile, {
23
+ get path() {
24
+ return joinPaths(context.entryPath, "completions", "powershell", "shared.ts");
25
+ },
26
+ builtinImports: { console: [
27
+ "white",
28
+ "green",
29
+ "red",
30
+ "bold",
31
+ "cyan",
32
+ "gray",
33
+ "magenta",
34
+ "magentaBright",
35
+ "greenBright",
36
+ "redBright",
37
+ "cyanBright",
38
+ "dim"
39
+ ] },
40
+ get children() {
41
+ return [
42
+ createComponent(Spacing, {}),
43
+ createComponent(VarDeclaration, {
44
+ "const": true,
45
+ "export": true,
46
+ name: "SHELL_COMPLETIONS",
47
+ get initializer() {
48
+ return code` \`# powershell completion for ${getAppTitle(context)}
2
49
 
3
50
  [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
4
- function __${h.value}_debug {
51
+ function __${name.value}_debug {
5
52
  if ($env:BASH_COMP_DEBUG_FILE) {
6
53
  "$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
7
54
  }
8
55
  }
9
56
 
10
- filter __${h.value}_escapeStringWithSpecialChars {
57
+ filter __${name.value}_escapeStringWithSpecialChars {
11
58
  $_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\\\`$&'
12
59
  }
13
60
 
14
- [scriptblock]$__${h.value}CompleterBlock = {
61
+ [scriptblock]$__${name.value}CompleterBlock = {
15
62
  param(
16
63
  $WordToComplete,
17
64
  $CommandAst,
@@ -22,9 +69,9 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
22
69
  $Command = $CommandAst.CommandElements
23
70
  $Command = "$Command"
24
71
 
25
- __${h.value}_debug ""
26
- __${h.value}_debug "========= starting completion logic =========="
27
- __${h.value}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
72
+ __${name.value}_debug ""
73
+ __${name.value}_debug "========= starting completion logic =========="
74
+ __${name.value}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
28
75
 
29
76
  # The user could have moved the cursor backwards on the command-line.
30
77
  # We need to trigger completion from the $CursorPosition location, so we need
@@ -34,24 +81,24 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
34
81
  if ($Command.Length -gt $CursorPosition) {
35
82
  $Command = $Command.Substring(0, $CursorPosition)
36
83
  }
37
- __${h.value}_debug "Truncated command: $Command"
84
+ __${name.value}_debug "Truncated command: $Command"
38
85
 
39
- $ShellCompDirectiveError=${t.CompletionDirectiveError}
40
- $ShellCompDirectiveNoSpace=${t.CompletionDirectiveNoSpace}
41
- $ShellCompDirectiveNoFileComp=${t.CompletionDirectiveNoFileComp}
42
- $ShellCompDirectiveFilterFileExt=${t.CompletionDirectiveFilterFileExt}
43
- $ShellCompDirectiveFilterDirs=${t.CompletionDirectiveFilterDirs}
44
- $ShellCompDirectiveKeepOrder=${t.CompletionDirectiveKeepOrder}
86
+ $ShellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}
87
+ $ShellCompDirectiveNoSpace=${CompletionDirective.CompletionDirectiveNoSpace}
88
+ $ShellCompDirectiveNoFileComp=${CompletionDirective.CompletionDirectiveNoFileComp}
89
+ $ShellCompDirectiveFilterFileExt=${CompletionDirective.CompletionDirectiveFilterFileExt}
90
+ $ShellCompDirectiveFilterDirs=${CompletionDirective.CompletionDirectiveFilterDirs}
91
+ $ShellCompDirectiveKeepOrder=${CompletionDirective.CompletionDirectiveKeepOrder}
45
92
 
46
93
  # Prepare the command to request completions for the program.
47
94
  # Split the command at the first space to separate the program and arguments.
48
95
  $Program, $Arguments = $Command.Split(" ", 2)
49
96
 
50
97
  $QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
51
- __${h.value}_debug "QuotedArgs: $QuotedArgs"
98
+ __${name.value}_debug "QuotedArgs: $QuotedArgs"
52
99
 
53
- $RequestComp = "& ${e} complete '--' $QuotedArgs"
54
- __${h.value}_debug "RequestComp: $RequestComp"
100
+ $RequestComp = "& ${EXEC_COMMAND} complete '--' $QuotedArgs"
101
+ __${name.value}_debug "RequestComp: $RequestComp"
55
102
 
56
103
  # we cannot use $WordToComplete because it
57
104
  # has the wrong values if the cursor was moved
@@ -59,13 +106,13 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
59
106
  if ($WordToComplete -ne "" ) {
60
107
  $WordToComplete = $Arguments.Split(" ")[-1]
61
108
  }
62
- __${h.value}_debug "New WordToComplete: $WordToComplete"
109
+ __${name.value}_debug "New WordToComplete: $WordToComplete"
63
110
 
64
111
 
65
112
  # Check for flag with equal sign
66
113
  $IsEqualFlag = ($WordToComplete -Like "--*=*" )
67
114
  if ( $IsEqualFlag ) {
68
- __${h.value}_debug "Completing equal sign flag"
115
+ __${name.value}_debug "Completing equal sign flag"
69
116
  # Remove the flag part
70
117
  $Flag, $WordToComplete = $WordToComplete.Split("=", 2)
71
118
  }
@@ -73,7 +120,7 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
73
120
  if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
74
121
  # If the last parameter is complete (there is a space following it)
75
122
  # We add an extra empty parameter so we can indicate this to the go method.
76
- __${h.value}_debug "Adding extra empty parameter"
123
+ __${name.value}_debug "Adding extra empty parameter"
77
124
  # PowerShell 7.2+ changed the way how the arguments are passed to executables,
78
125
  # so for pre-7.2 or when Legacy argument passing is enabled we need to use
79
126
  if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
@@ -86,7 +133,7 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
86
133
  }
87
134
  }
88
135
 
89
- __${h.value}_debug "Calling $RequestComp"
136
+ __${name.value}_debug "Calling $RequestComp"
90
137
  # First disable ActiveHelp which is not supported for Powershell
91
138
  $env:ActiveHelp = 0
92
139
 
@@ -100,14 +147,14 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
100
147
  # There is no directive specified
101
148
  $Directive = 0
102
149
  }
103
- __${h.value}_debug "The completion directive is: $Directive"
150
+ __${name.value}_debug "The completion directive is: $Directive"
104
151
 
105
152
  # remove directive (last element) from out
106
153
  $Out = $Out | Where-Object { $_ -ne $Out[-1] }
107
- __${h.value}_debug "The completions are: $Out"
154
+ __${name.value}_debug "The completions are: $Out"
108
155
  if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
109
156
  # Error code. No completion.
110
- __${h.value}_debug "Received error from custom completion go code"
157
+ __${name.value}_debug "Received error from custom completion go code"
111
158
  return
112
159
  }
113
160
 
@@ -115,7 +162,7 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
115
162
  [Array]$Values = $Out | ForEach-Object {
116
163
  # Split the output in name and description
117
164
  $Name, $Description = $_.Split("\\\`t", 2)
118
- __${h.value}_debug "Name: $Name Description: $Description"
165
+ __${name.value}_debug "Name: $Name Description: $Description"
119
166
 
120
167
  # Look for the longest completion so that we can format things nicely
121
168
  if ($Longest -lt $Name.Length) {
@@ -134,13 +181,13 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
134
181
  $Space = " "
135
182
  if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
136
183
  # remove the space here
137
- __${h.value}_debug "ShellCompDirectiveNoSpace is called"
184
+ __${name.value}_debug "ShellCompDirectiveNoSpace is called"
138
185
  $Space = ""
139
186
  }
140
187
 
141
188
  if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
142
189
  (($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
143
- __${h.value}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
190
+ __${name.value}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
144
191
 
145
192
  # return here to prevent the completion of the extensions
146
193
  return
@@ -152,7 +199,7 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
152
199
 
153
200
  # Join the flag back if we have an equal sign flag
154
201
  if ( $IsEqualFlag ) {
155
- __${h.value}_debug "Join the equal sign flag back to the completion value"
202
+ __${name.value}_debug "Join the equal sign flag back to the completion value"
156
203
  $_.Name = $Flag + "=" + $_.Name
157
204
  }
158
205
  }
@@ -163,7 +210,7 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
163
210
  }
164
211
 
165
212
  if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
166
- __${h.value}_debug "ShellCompDirectiveNoFileComp is called"
213
+ __${name.value}_debug "ShellCompDirectiveNoFileComp is called"
167
214
 
168
215
  if ($Values.Length -eq 0) {
169
216
  # Just print an empty string here so the
@@ -177,7 +224,7 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
177
224
 
178
225
  # Get the current mode
179
226
  $Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
180
- __${h.value}_debug "Mode: $Mode"
227
+ __${name.value}_debug "Mode: $Mode"
181
228
 
182
229
  $Values | ForEach-Object {
183
230
 
@@ -202,10 +249,10 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
202
249
  "Complete" {
203
250
 
204
251
  if ($Values.Length -eq 1) {
205
- __${h.value}_debug "Only one completion left"
252
+ __${name.value}_debug "Only one completion left"
206
253
 
207
254
  # insert space after value
208
- [System.Management.Automation.CompletionResult]::new($($comp.Name | __${h.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
255
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${name.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
209
256
 
210
257
  } else {
211
258
  # Add the proper number of spaces to align the descriptions
@@ -229,7 +276,7 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
229
276
  # insert space after value
230
277
  # MenuComplete will automatically show the ToolTip of
231
278
  # the highlighted value at the bottom of the suggestions.
232
- [System.Management.Automation.CompletionResult]::new($($comp.Name | __${h.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
279
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${name.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
233
280
  }
234
281
 
235
282
  # TabCompleteNext and in case we get something unknown
@@ -237,14 +284,22 @@ import{EXEC_COMMAND as e}from"../helpers/complete-command.mjs";import{Completion
237
284
  # Like MenuComplete but we don't want to add a space here because
238
285
  # the user need to press space anyway to get the completion.
239
286
  # Description will not be shown because that's not possible with TabCompleteNext
240
- [System.Management.Automation.CompletionResult]::new($($comp.Name | __${h.value}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
287
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${name.value}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
241
288
  }
242
289
  }
243
290
  }
244
291
  }
245
292
 
246
- Register-ArgumentCompleter -CommandName '${m.value}' -ScriptBlock $__${h.value}CompleterBlock
247
- \`; `}}),n(c,{}),n(s,{export:!0,const:!0,name:`SHELL_COMPLETIONS_DISPLAY`,initializer:a` SHELL_COMPLETIONS.split("\\n").map(line => {
293
+ Register-ArgumentCompleter -CommandName '${bin.value}' -ScriptBlock $__${name.value}CompleterBlock
294
+ \`; `;
295
+ }
296
+ }),
297
+ createComponent(Spacing, {}),
298
+ createComponent(VarDeclaration, {
299
+ "export": true,
300
+ "const": true,
301
+ name: "SHELL_COMPLETIONS_DISPLAY",
302
+ initializer: code` SHELL_COMPLETIONS.split("\\n").map(line => {
248
303
  if (!line.trim()) {
249
304
  return "";
250
305
  }
@@ -265,5 +320,13 @@ Register-ArgumentCompleter -CommandName '${m.value}' -ScriptBlock $__${h.value}C
265
320
  .replaceAll(/\\$?__\\w/g, bold(magentaBright("$&")))
266
321
  .replaceAll(/(?<=\\s)(-\\w|--\\w[\\w-]*)(?=\\s|$)/g, bold(magenta("$&")));
267
322
 
268
- }).join("\\n"); `})]}})}export{p as PowerShellCompletionsShared};
323
+ }).join("\\n"); `
324
+ })
325
+ ];
326
+ }
327
+ });
328
+ }
329
+
330
+ //#endregion
331
+ export { PowerShellCompletionsShared };
269
332
  //# sourceMappingURL=powershell-shared.mjs.map