@shell-shock/plugin-completions 0.2.23 → 0.3.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 (133) hide show
  1. package/README.md +1 -1
  2. package/dist/components/bash-config-command.cjs +132 -0
  3. package/dist/components/bash-config-command.d.cts +10 -0
  4. package/dist/components/bash-config-command.d.cts.map +1 -0
  5. package/dist/components/bash-config-command.d.mts +10 -0
  6. package/dist/components/bash-config-command.d.mts.map +1 -0
  7. package/dist/components/bash-config-command.mjs +132 -0
  8. package/dist/components/bash-config-command.mjs.map +1 -0
  9. package/dist/components/bash-script-command.cjs +106 -0
  10. package/dist/components/bash-script-command.d.cts +10 -0
  11. package/dist/components/bash-script-command.d.cts.map +1 -0
  12. package/dist/components/bash-script-command.d.mts +10 -0
  13. package/dist/components/bash-script-command.d.mts.map +1 -0
  14. package/dist/components/bash-script-command.mjs +106 -0
  15. package/dist/components/bash-script-command.mjs.map +1 -0
  16. package/dist/components/bash-shared.cjs +172 -0
  17. package/dist/components/bash-shared.d.cts +10 -0
  18. package/dist/components/bash-shared.d.cts.map +1 -0
  19. package/dist/components/bash-shared.d.mts +10 -0
  20. package/dist/components/bash-shared.d.mts.map +1 -0
  21. package/dist/components/bash-shared.mjs +172 -0
  22. package/dist/components/bash-shared.mjs.map +1 -0
  23. package/dist/components/fish-config-command.cjs +132 -0
  24. package/dist/components/fish-config-command.d.cts +10 -0
  25. package/dist/components/fish-config-command.d.cts.map +1 -0
  26. package/dist/components/fish-config-command.d.mts +10 -0
  27. package/dist/components/fish-config-command.d.mts.map +1 -0
  28. package/dist/components/fish-config-command.mjs +132 -0
  29. package/dist/components/fish-config-command.mjs.map +1 -0
  30. package/dist/components/fish-script-command.cjs +106 -0
  31. package/dist/components/fish-script-command.d.cts +10 -0
  32. package/dist/components/fish-script-command.d.cts.map +1 -0
  33. package/dist/components/fish-script-command.d.mts +10 -0
  34. package/dist/components/fish-script-command.d.mts.map +1 -0
  35. package/dist/components/fish-script-command.mjs +106 -0
  36. package/dist/components/fish-script-command.mjs.map +1 -0
  37. package/dist/components/fish-shared.cjs +303 -0
  38. package/dist/components/fish-shared.d.cts +10 -0
  39. package/dist/components/fish-shared.d.cts.map +1 -0
  40. package/dist/components/fish-shared.d.mts +10 -0
  41. package/dist/components/fish-shared.d.mts.map +1 -0
  42. package/dist/components/fish-shared.mjs +303 -0
  43. package/dist/components/fish-shared.mjs.map +1 -0
  44. package/dist/components/index.cjs +24 -8
  45. package/dist/components/index.d.cts +13 -5
  46. package/dist/components/index.d.mts +13 -5
  47. package/dist/components/index.mjs +13 -5
  48. package/dist/components/powershell-config-command.cjs +128 -0
  49. package/dist/components/powershell-config-command.d.cts +7 -0
  50. package/dist/components/powershell-config-command.d.cts.map +1 -0
  51. package/dist/components/powershell-config-command.d.mts +7 -0
  52. package/dist/components/powershell-config-command.d.mts.map +1 -0
  53. package/dist/components/powershell-config-command.mjs +128 -0
  54. package/dist/components/powershell-config-command.mjs.map +1 -0
  55. package/dist/components/powershell-script-command.cjs +106 -0
  56. package/dist/components/powershell-script-command.d.cts +10 -0
  57. package/dist/components/powershell-script-command.d.cts.map +1 -0
  58. package/dist/components/powershell-script-command.d.mts +10 -0
  59. package/dist/components/powershell-script-command.d.mts.map +1 -0
  60. package/dist/components/powershell-script-command.mjs +106 -0
  61. package/dist/components/powershell-script-command.mjs.map +1 -0
  62. package/dist/components/powershell-shared.cjs +319 -0
  63. package/dist/components/powershell-shared.d.cts +10 -0
  64. package/dist/components/powershell-shared.d.cts.map +1 -0
  65. package/dist/components/powershell-shared.d.mts +10 -0
  66. package/dist/components/powershell-shared.d.mts.map +1 -0
  67. package/dist/components/{powershell-command.mjs → powershell-shared.mjs} +81 -181
  68. package/dist/components/powershell-shared.mjs.map +1 -0
  69. package/dist/components/zsh-config-command.cjs +132 -0
  70. package/dist/components/zsh-config-command.d.cts +10 -0
  71. package/dist/components/zsh-config-command.d.cts.map +1 -0
  72. package/dist/components/zsh-config-command.d.mts +10 -0
  73. package/dist/components/zsh-config-command.d.mts.map +1 -0
  74. package/dist/components/zsh-config-command.mjs +132 -0
  75. package/dist/components/zsh-config-command.mjs.map +1 -0
  76. package/dist/components/zsh-script-command.cjs +111 -0
  77. package/dist/components/zsh-script-command.d.cts +10 -0
  78. package/dist/components/zsh-script-command.d.cts.map +1 -0
  79. package/dist/components/zsh-script-command.d.mts +10 -0
  80. package/dist/components/zsh-script-command.d.mts.map +1 -0
  81. package/dist/components/zsh-script-command.mjs +111 -0
  82. package/dist/components/zsh-script-command.mjs.map +1 -0
  83. package/dist/components/zsh-shared.cjs +281 -0
  84. package/dist/components/zsh-shared.d.cts +10 -0
  85. package/dist/components/zsh-shared.d.cts.map +1 -0
  86. package/dist/components/zsh-shared.d.mts +10 -0
  87. package/dist/components/zsh-shared.d.mts.map +1 -0
  88. package/dist/components/zsh-shared.mjs +281 -0
  89. package/dist/components/zsh-shared.mjs.map +1 -0
  90. package/dist/helpers/complete-command.cjs +2 -7
  91. package/dist/helpers/complete-command.d.cts +2 -2
  92. package/dist/helpers/complete-command.d.cts.map +1 -1
  93. package/dist/helpers/complete-command.d.mts +2 -2
  94. package/dist/helpers/complete-command.d.mts.map +1 -1
  95. package/dist/helpers/complete-command.mjs +2 -7
  96. package/dist/helpers/complete-command.mjs.map +1 -1
  97. package/dist/helpers/index.cjs +1 -1
  98. package/dist/helpers/index.d.cts +2 -2
  99. package/dist/helpers/index.d.mts +2 -2
  100. package/dist/helpers/index.mjs +2 -2
  101. package/dist/index.cjs +245 -59
  102. package/dist/index.d.cts.map +1 -1
  103. package/dist/index.d.mts.map +1 -1
  104. package/dist/index.mjs +246 -60
  105. package/dist/index.mjs.map +1 -1
  106. package/package.json +148 -37
  107. package/dist/components/bash-command.cjs +0 -273
  108. package/dist/components/bash-command.d.cts +0 -10
  109. package/dist/components/bash-command.d.cts.map +0 -1
  110. package/dist/components/bash-command.d.mts +0 -10
  111. package/dist/components/bash-command.d.mts.map +0 -1
  112. package/dist/components/bash-command.mjs +0 -273
  113. package/dist/components/bash-command.mjs.map +0 -1
  114. package/dist/components/fish-command.cjs +0 -403
  115. package/dist/components/fish-command.d.cts +0 -10
  116. package/dist/components/fish-command.d.cts.map +0 -1
  117. package/dist/components/fish-command.d.mts +0 -10
  118. package/dist/components/fish-command.d.mts.map +0 -1
  119. package/dist/components/fish-command.mjs +0 -403
  120. package/dist/components/fish-command.mjs.map +0 -1
  121. package/dist/components/powershell-command.cjs +0 -419
  122. package/dist/components/powershell-command.d.cts +0 -10
  123. package/dist/components/powershell-command.d.cts.map +0 -1
  124. package/dist/components/powershell-command.d.mts +0 -10
  125. package/dist/components/powershell-command.d.mts.map +0 -1
  126. package/dist/components/powershell-command.mjs.map +0 -1
  127. package/dist/components/zsh-command.cjs +0 -384
  128. package/dist/components/zsh-command.d.cts +0 -10
  129. package/dist/components/zsh-command.d.cts.map +0 -1
  130. package/dist/components/zsh-command.d.mts +0 -10
  131. package/dist/components/zsh-command.d.mts.map +0 -1
  132. package/dist/components/zsh-command.mjs +0 -384
  133. package/dist/components/zsh-command.mjs.map +0 -1
@@ -1,384 +0,0 @@
1
- import { exec } from "../helpers/complete-command.mjs";
2
- import { CompletionDirective } from "../helpers/completion-directive-constants.mjs";
3
- import { createComponent, memo } from "@alloy-js/core/jsx-runtime";
4
- import { getAppBin, getAppTitle } from "@shell-shock/core/plugin-utils";
5
- import { joinPaths } from "@stryke/path";
6
- import { code } from "@alloy-js/core";
7
- import { FunctionDeclaration, IfStatement, InterfaceDeclaration, VarDeclaration } from "@alloy-js/typescript";
8
- import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
9
- import { Spacing } from "@powerlines/plugin-alloy/core";
10
- import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
11
- import { InterfaceMember, TypescriptFile } from "@powerlines/plugin-alloy/typescript";
12
- import { TSDoc, TSDocDefaultValue, TSDocRemarks } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
13
- import { snakeCase } from "@stryke/string-format";
14
-
15
- //#region src/components/zsh-command.tsx
16
- /**
17
- * The Zsh Completions commands' handler wrapper for the Shell Shock project.
18
- */
19
- function ZshCompletionsCommand() {
20
- const context = usePowerlines();
21
- return createComponent(TypescriptFile, {
22
- get path() {
23
- return joinPaths(context.entryPath, "completions", "zsh", "command.ts");
24
- },
25
- imports: {
26
- "node:os": ["os"],
27
- "node:fs/promises": ["readFile", "writeFile"]
28
- },
29
- builtinImports: { "shell-shock:console": [
30
- "colors",
31
- "writeLine",
32
- "success",
33
- "warn",
34
- "stripAnsi"
35
- ] },
36
- get children() {
37
- return [
38
- createComponent(TSDoc, { heading: "Options for the Zsh completions command." }),
39
- createComponent(InterfaceDeclaration, {
40
- "export": true,
41
- name: "ZshCompletionsOptions",
42
- get children() {
43
- return [
44
- createComponent(TSDoc, {
45
- heading: "The path to write the completion script to.",
46
- get children() {
47
- return [createComponent(TSDocRemarks, { children: `If no extension is provided, the \`.zsh\` extension will be used.` }), createComponent(TSDocDefaultValue, {
48
- get type() {
49
- return ReflectionKind.string;
50
- },
51
- get defaultValue() {
52
- return `${getAppBin(context)}-completions.zsh`;
53
- }
54
- })];
55
- }
56
- }),
57
- createComponent(InterfaceMember, {
58
- name: "script",
59
- optional: true,
60
- type: "string | true"
61
- }),
62
- createComponent(Spacing, {}),
63
- createComponent(TSDoc, {
64
- heading: "The Zsh configuration file to append the completion script to.",
65
- get children() {
66
- return [createComponent(TSDocRemarks, { children: `The generated completion script will be appended to the specified configuration file. Possible values for the Zsh configuration file include: \\n- \`~/.zshrc\` \\n- \`~/.zprofile\`` }), createComponent(TSDocDefaultValue, {
67
- get type() {
68
- return ReflectionKind.string;
69
- },
70
- defaultValue: "~/.zshrc"
71
- })];
72
- }
73
- }),
74
- createComponent(InterfaceMember, {
75
- name: "config",
76
- optional: true,
77
- type: "string | true"
78
- })
79
- ];
80
- }
81
- }),
82
- createComponent(Spacing, {}),
83
- createComponent(TSDoc, { heading: "Handler logic for the \\`completions zsh\\` command." }),
84
- createComponent(FunctionDeclaration, {
85
- "export": true,
86
- "default": true,
87
- async: true,
88
- name: "handler",
89
- parameters: [{
90
- name: "options",
91
- type: "ZshCompletionsOptions"
92
- }],
93
- get children() {
94
- return [
95
- createComponent(VarDeclaration, {
96
- "const": true,
97
- name: "completions",
98
- type: "string",
99
- get initializer() {
100
- return code`#compdef ${getAppBin(context)}
101
- compdef _${snakeCase(getAppBin(context))} ${getAppBin(context)}
102
-
103
- # zsh completion for ${getAppTitle(context)} -*- shell-script -*-
104
-
105
- __${snakeCase(getAppBin(context))}_debug() {
106
- local file="$BASH_COMP_DEBUG_FILE"
107
- if [[ -n \${file} ]]; then
108
- echo "$*" >> "\${file}"
109
- fi
110
- }
111
-
112
- _${getAppBin(context)}() {
113
- local shellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}
114
- local shellCompDirectiveNoSpace=${CompletionDirective.CompletionDirectiveNoSpace}
115
- local shellCompDirectiveNoFileComp=${CompletionDirective.CompletionDirectiveNoFileComp}
116
- local shellCompDirectiveFilterFileExt=${CompletionDirective.CompletionDirectiveFilterFileExt}
117
- local shellCompDirectiveFilterDirs=${CompletionDirective.CompletionDirectiveFilterDirs}
118
- local shellCompDirectiveKeepOrder=${CompletionDirective.CompletionDirectiveKeepOrder}
119
-
120
- local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
121
- local -a completions
122
-
123
- __${snakeCase(getAppBin(context))}_debug "\\n========= starting completion logic =========="
124
- __${snakeCase(getAppBin(context))}_debug "CURRENT: \${CURRENT}, words[*]: \${words[*]}"
125
-
126
- # The user could have moved the cursor backwards on the command-line.
127
- # We need to trigger completion from the $CURRENT location, so we need
128
- # to truncate the command-line ($words) up to the $CURRENT location.
129
- # (We cannot use $CURSOR as its value does not work when a command is an alias.)
130
- words=( "\${=words[1,CURRENT]}" )
131
- __${snakeCase(getAppBin(context))}_debug "Truncated words[*]: \${words[*]},"
132
-
133
- lastParam=\${words[-1]}
134
- lastChar=\${lastParam[-1]}
135
- __${snakeCase(getAppBin(context))}_debug "lastParam: \${lastParam}, lastChar: \${lastChar}"
136
- # For zsh, when completing a flag with an = (e.g., ${getAppBin(context)} -n=<TAB>)
137
- # completions must be prefixed with the flag
138
- setopt local_options BASH_REMATCH
139
- if [[ "\${lastParam}" =~ '-.*=' ]]; then
140
- # We are dealing with a flag with an =
141
- flagPrefix="-P \${BASH_REMATCH}"
142
- fi
143
-
144
- # Prepare the command to obtain completions, ensuring arguments are quoted for eval
145
- local -a args_to_quote=("\${(@)words[2,-1]}")
146
- if [ "\${lastChar}" = "" ]; then
147
- # If the last parameter is complete (there is a space following it)
148
- # We add an extra empty parameter so we can indicate this to the go completion code.
149
- __${snakeCase(getAppBin(context))}_debug "Adding extra empty parameter"
150
- args_to_quote+=("")
151
- fi
152
-
153
- # Use Zsh's (q) flag to quote each argument safely for eval
154
- local quoted_args=("\${(@q)args_to_quote}")
155
-
156
- # Join the main command and the quoted arguments into a single string for eval
157
- requestComp="${exec} complete -- \${quoted_args[*]}"
158
-
159
- __${snakeCase(getAppBin(context))}_debug "About to call: eval \${requestComp}"
160
-
161
- # Use eval to handle any environment variables and such
162
- out=$(eval \${requestComp} 2>/dev/null)
163
- __${snakeCase(getAppBin(context))}_debug "completion output: \${out}"
164
-
165
- # Extract the directive integer following a : from the last line
166
- local lastLine
167
- while IFS='\n' read -r line; do
168
- lastLine=\${line}
169
- done < <(printf "%s\n" "\${out[@]}")
170
- __${snakeCase(getAppBin(context))}_debug "last line: \${lastLine}"
171
-
172
- if [ "\${lastLine[1]}" = : ]; then
173
- directive=\${lastLine[2,-1]}
174
- # Remove the directive including the : and the newline
175
- local suffix
176
- (( suffix=\${#lastLine}+2))
177
- out=\${out[1,-$suffix]}
178
- else
179
- # There is no directive specified. Leave $out as is.
180
- __${snakeCase(getAppBin(context))}_debug "No directive found. Setting to default"
181
- directive=0
182
- fi
183
-
184
- __${snakeCase(getAppBin(context))}_debug "directive: \${directive}"
185
- __${snakeCase(getAppBin(context))}_debug "completions: \${out}"
186
- __${snakeCase(getAppBin(context))}_debug "flagPrefix: \${flagPrefix}"
187
-
188
- if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
189
- __${snakeCase(getAppBin(context))}_debug "Completion received error. Ignoring completions."
190
- return
191
- fi
192
-
193
- local activeHelpMarker="%"
194
- local endIndex=\${#activeHelpMarker}
195
- local startIndex=$((\${#activeHelpMarker}+1))
196
- local hasActiveHelp=0
197
- while IFS='\n' read -r comp; do
198
- # Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
199
- if [ "\${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
200
- __${snakeCase(getAppBin(context))}_debug "ActiveHelp found: $comp"
201
- comp="\${comp[$startIndex,-1]}"
202
- if [ -n "$comp" ]; then
203
- compadd -x "\${comp}"
204
- __${snakeCase(getAppBin(context))}_debug "ActiveHelp will need delimiter"
205
- hasActiveHelp=1
206
- fi
207
- continue
208
- fi
209
-
210
- if [ -n "$comp" ]; then
211
- # If requested, completions are returned with a description.
212
- # The description is preceded by a TAB character.
213
- # For zsh's _describe, we need to use a : instead of a TAB.
214
- # We first need to escape any : as part of the completion itself.
215
- comp=\${comp//:/\\:}
216
-
217
- local tab="$(printf '\\t')"
218
- comp=\${comp//$tab/:}
219
-
220
- __${snakeCase(getAppBin(context))}_debug "Adding completion: \${comp}"
221
- completions+=\${comp}
222
- lastComp=$comp
223
- fi
224
- done < <(printf "%s\n" "\${out[@]}")
225
-
226
- # Add a delimiter after the activeHelp statements, but only if:
227
- # - there are completions following the activeHelp statements, or
228
- # - file completion will be performed (so there will be choices after the activeHelp)
229
- if [ $hasActiveHelp -eq 1 ]; then
230
- if [ \${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
231
- __${snakeCase(getAppBin(context))}_debug "Adding activeHelp delimiter"
232
- compadd -x "--"
233
- hasActiveHelp=0
234
- fi
235
- fi
236
-
237
- if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
238
- __${snakeCase(getAppBin(context))}_debug "Activating nospace."
239
- noSpace="-S ''"
240
- fi
241
-
242
- if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
243
- __${snakeCase(getAppBin(context))}_debug "Activating keep order."
244
- keepOrder="-V"
245
- fi
246
-
247
- if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
248
- # File extension filtering
249
- local filteringCmd
250
- filteringCmd='_files'
251
- for filter in \${completions[@]}; do
252
- if [ \${filter[1]} != '*' ]; then
253
- # zsh requires a glob pattern to do file filtering
254
- filter="\\*.$filter"
255
- fi
256
- filteringCmd+=" -g $filter"
257
- done
258
- filteringCmd+=" \${flagPrefix}"
259
-
260
- __${snakeCase(getAppBin(context))}_debug "File filtering command: $filteringCmd"
261
- _arguments '*:filename:'"$filteringCmd"
262
- elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
263
- # File completion for directories only
264
- local subdir
265
- subdir="\${completions[1]}"
266
- if [ -n "$subdir" ]; then
267
- __${snakeCase(getAppBin(context))}_debug "Listing directories in $subdir"
268
- pushd "\${subdir}" >/dev/null 2>&1
269
- else
270
- __${snakeCase(getAppBin(context))}_debug "Listing directories in ."
271
- fi
272
-
273
- local result
274
- _arguments '*:dirname:_files -/'" \${flagPrefix}"
275
- result=$?
276
- if [ -n "$subdir" ]; then
277
- popd >/dev/null 2>&1
278
- fi
279
- return $result
280
- else
281
- __${snakeCase(getAppBin(context))}_debug "Calling _describe"
282
- if eval _describe $keepOrder "completions" completions -Q \${flagPrefix} \${noSpace}; then
283
- __${snakeCase(getAppBin(context))}_debug "_describe found some completions"
284
-
285
- # Return the success of having called _describe
286
- return 0
287
- else
288
- __${snakeCase(getAppBin(context))}_debug "_describe did not find completions."
289
- __${snakeCase(getAppBin(context))}_debug "Checking if we should do file completion."
290
- if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
291
- __${snakeCase(getAppBin(context))}_debug "deactivating file completion"
292
-
293
- # Return 0 to indicate completion is finished and prevent zsh from
294
- # trying other completion algorithms (which could cause hanging).
295
- # We use NoFileComp directive to explicitly disable file completion.
296
- return 0
297
- else
298
- # Perform file completion
299
- __${snakeCase(getAppBin(context))}_debug "Activating file completion"
300
-
301
- # We must return the result of this command, so it must be the
302
- # last command, or else we must store its result to return it.
303
- _arguments '*:filename:_files'" \${flagPrefix}"
304
- fi
305
- fi
306
- fi
307
- }
308
-
309
- # don't run the completion function when being sourced or eval-ed
310
- if [ "\${funcstack[1]}" = "_${snakeCase(getAppBin(context))}" ]; then
311
- _${snakeCase(getAppBin(context))}
312
- fi
313
- \`);`;
314
- }
315
- }),
316
- createComponent(Spacing, {}),
317
- createComponent(IfStatement, {
318
- condition: code`options.config`,
319
- get children() {
320
- return [
321
- createComponent(VarDeclaration, {
322
- "let": true,
323
- name: "configFilePath",
324
- type: "string",
325
- initializer: code`options.config === true ? "~/.zshrc" : options.config`
326
- }),
327
- createComponent(Spacing, {}),
328
- createComponent(IfStatement, {
329
- condition: code`configFilePath.startsWith("~")`,
330
- children: code`configFilePath = join(os.homedir(), configFilePath.replace("~", "")); `
331
- }),
332
- createComponent(Spacing, {}),
333
- createComponent(VarDeclaration, {
334
- "let": true,
335
- name: "configFileContent",
336
- type: "string",
337
- initializer: code`"";`
338
- }),
339
- createComponent(Spacing, {}),
340
- memo(() => code`try {
341
- configFileContent = await readFile(configFilePath, "utf8");
342
- } catch (error) {
343
- if (error.code === "ENOENT") {
344
- // If the file doesn't exist, we can create it later when writing the completion script.
345
- warn(\`Configuration file \${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\`);
346
- } else {
347
- return { error };
348
- }
349
- }
350
-
351
- await writeFile(configFilePath, \`\${configFileContent}\\n\\n\${stripAnsi(completions)}\`);
352
-
353
- success(\`${getAppTitle(context)} Zsh completion script has been generated and appended to \${colors.bold(configFilePath)}. Please restart your terminal or run \`source \${configFilePath}\` to apply the changes.\`); `)
354
- ];
355
- }
356
- }),
357
- createComponent(Spacing, {}),
358
- createComponent(IfStatement, {
359
- condition: code`options.script`,
360
- get children() {
361
- return code`const outputPath = options.script === true ? "${getAppBin(context)}-completions.zsh" : options.script;
362
- await writeFile(outputPath, stripAnsi(completions));
363
-
364
- success(\`${getAppTitle(context)} Zsh completion script has been generated at \${colors.bold(outputPath)}.\`);`;
365
- }
366
- }),
367
- createComponent(Spacing, {}),
368
- createComponent(IfStatement, {
369
- condition: code`!options.config && !options.script`,
370
- children: code`writeLine(" ------------------------------------------------- ");
371
- writeLine(completions);
372
- writeLine(" ------------------------------------------------- ");`
373
- })
374
- ];
375
- }
376
- })
377
- ];
378
- }
379
- });
380
- }
381
-
382
- //#endregion
383
- export { ZshCompletionsCommand };
384
- //# sourceMappingURL=zsh-command.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zsh-command.mjs","names":[],"sources":["../../src/components/zsh-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\";\nimport { exec } from \"../helpers/complete-command\";\nimport { CompletionDirective } from \"../helpers/completion-directive-constants\";\nimport type { CompletionsPluginContext } from \"../types/plugin\";\n\n/**\n * The Zsh Completions commands' handler wrapper for the Shell Shock project.\n */\nexport function ZshCompletionsCommand() {\n const context = usePowerlines<CompletionsPluginContext>();\n\n return (\n <TypescriptFile\n path={joinPaths(context.entryPath, \"completions\", \"zsh\", \"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 Zsh completions command.\" />\n <InterfaceDeclaration export name=\"ZshCompletionsOptions\">\n <TSDoc heading=\"The path to write the completion script to.\">\n <TSDocRemarks>{`If no extension is provided, the \\`.zsh\\` extension will be used.`}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue={`${getAppBin(context)}-completions.zsh`}\n />\n </TSDoc>\n <InterfaceMember name=\"script\" optional type=\"string | true\" />\n <Spacing />\n <TSDoc heading=\"The Zsh 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 Zsh configuration file include: \\\\n- \\`~/.zshrc\\` \\\\n- \\`~/.zprofile\\``}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue=\"~/.zshrc\"\n />\n </TSDoc>\n <InterfaceMember name=\"config\" optional type=\"string | true\" />\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc heading=\"Handler logic for the \\`completions zsh\\` command.\"></TSDoc>\n <FunctionDeclaration\n export\n default\n async\n name=\"handler\"\n parameters={[{ name: \"options\", type: \"ZshCompletionsOptions\" }]}>\n <VarDeclaration\n const\n name=\"completions\"\n type=\"string\"\n initializer={code`#compdef ${getAppBin(context)}\ncompdef _${snakeCase(getAppBin(context))} ${getAppBin(context)}\n\n# zsh completion for ${getAppTitle(context)} -*- shell-script -*-\n\n__${snakeCase(getAppBin(context))}_debug() {\n local file=\"$BASH_COMP_DEBUG_FILE\"\n if [[ -n \\${file} ]]; then\n echo \"$*\" >> \"\\${file}\"\n fi\n}\n\n_${getAppBin(context)}() {\n local shellCompDirectiveError=${\n CompletionDirective.CompletionDirectiveError\n }\n local shellCompDirectiveNoSpace=${\n CompletionDirective.CompletionDirectiveNoSpace\n }\n local shellCompDirectiveNoFileComp=${\n CompletionDirective.CompletionDirectiveNoFileComp\n }\n local shellCompDirectiveFilterFileExt=${\n CompletionDirective.CompletionDirectiveFilterFileExt\n }\n local shellCompDirectiveFilterDirs=${\n CompletionDirective.CompletionDirectiveFilterDirs\n }\n local shellCompDirectiveKeepOrder=${\n CompletionDirective.CompletionDirectiveKeepOrder\n }\n\n local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder\n local -a completions\n\n __${snakeCase(getAppBin(context))}_debug \"\\\\n========= starting completion logic ==========\"\n __${snakeCase(getAppBin(context))}_debug \"CURRENT: \\${CURRENT}, words[*]: \\${words[*]}\"\n\n # The user could have moved the cursor backwards on the command-line.\n # We need to trigger completion from the $CURRENT location, so we need\n # to truncate the command-line ($words) up to the $CURRENT location.\n # (We cannot use $CURSOR as its value does not work when a command is an alias.)\n words=( \"\\${=words[1,CURRENT]}\" )\n __${snakeCase(getAppBin(context))}_debug \"Truncated words[*]: \\${words[*]},\"\n\n lastParam=\\${words[-1]}\n lastChar=\\${lastParam[-1]}\n __${snakeCase(getAppBin(context))}_debug \"lastParam: \\${lastParam}, lastChar: \\${lastChar}\"\n # For zsh, when completing a flag with an = (e.g., ${getAppBin(\n context\n )} -n=<TAB>)\n # completions must be prefixed with the flag\n setopt local_options BASH_REMATCH\n if [[ \"\\${lastParam}\" =~ '-.*=' ]]; then\n # We are dealing with a flag with an =\n flagPrefix=\"-P \\${BASH_REMATCH}\"\n fi\n\n # Prepare the command to obtain completions, ensuring arguments are quoted for eval\n local -a args_to_quote=(\"\\${(@)words[2,-1]}\")\n if [ \"\\${lastChar}\" = \"\" ]; then\n # If the last parameter is complete (there is a space following it)\n # We add an extra empty parameter so we can indicate this to the go completion code.\n __${snakeCase(getAppBin(context))}_debug \"Adding extra empty parameter\"\n args_to_quote+=(\"\")\n fi\n\n # Use Zsh's (q) flag to quote each argument safely for eval\n local quoted_args=(\"\\${(@q)args_to_quote}\")\n\n # Join the main command and the quoted arguments into a single string for eval\n requestComp=\"${exec} complete -- \\${quoted_args[*]}\"\n\n __${snakeCase(getAppBin(context))}_debug \"About to call: eval \\${requestComp}\"\n\n # Use eval to handle any environment variables and such\n out=$(eval \\${requestComp} 2>/dev/null)\n __${snakeCase(getAppBin(context))}_debug \"completion output: \\${out}\"\n\n # Extract the directive integer following a : from the last line\n local lastLine\n while IFS='\\n' read -r line; do\n lastLine=\\${line}\n done < <(printf \"%s\\n\" \"\\${out[@]}\")\n __${snakeCase(getAppBin(context))}_debug \"last line: \\${lastLine}\"\n\n if [ \"\\${lastLine[1]}\" = : ]; then\n directive=\\${lastLine[2,-1]}\n # Remove the directive including the : and the newline\n local suffix\n (( suffix=\\${#lastLine}+2))\n out=\\${out[1,-$suffix]}\n else\n # There is no directive specified. Leave $out as is.\n __${snakeCase(getAppBin(context))}_debug \"No directive found. Setting to default\"\n directive=0\n fi\n\n __${snakeCase(getAppBin(context))}_debug \"directive: \\${directive}\"\n __${snakeCase(getAppBin(context))}_debug \"completions: \\${out}\"\n __${snakeCase(getAppBin(context))}_debug \"flagPrefix: \\${flagPrefix}\"\n\n if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then\n __${snakeCase(getAppBin(context))}_debug \"Completion received error. Ignoring completions.\"\n return\n fi\n\n local activeHelpMarker=\"%\"\n local endIndex=\\${#activeHelpMarker}\n local startIndex=$((\\${#activeHelpMarker}+1))\n local hasActiveHelp=0\n while IFS='\\n' read -r comp; do\n # Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)\n if [ \"\\${comp[1,$endIndex]}\" = \"$activeHelpMarker\" ];then\n __${snakeCase(getAppBin(context))}_debug \"ActiveHelp found: $comp\"\n comp=\"\\${comp[$startIndex,-1]}\"\n if [ -n \"$comp\" ]; then\n compadd -x \"\\${comp}\"\n __${snakeCase(getAppBin(context))}_debug \"ActiveHelp will need delimiter\"\n hasActiveHelp=1\n fi\n continue\n fi\n\n if [ -n \"$comp\" ]; then\n # If requested, completions are returned with a description.\n # The description is preceded by a TAB character.\n # For zsh's _describe, we need to use a : instead of a TAB.\n # We first need to escape any : as part of the completion itself.\n comp=\\${comp//:/\\\\:}\n\n local tab=\"$(printf '\\\\t')\"\n comp=\\${comp//$tab/:}\n\n __${snakeCase(getAppBin(context))}_debug \"Adding completion: \\${comp}\"\n completions+=\\${comp}\n lastComp=$comp\n fi\n done < <(printf \"%s\\n\" \"\\${out[@]}\")\n\n # Add a delimiter after the activeHelp statements, but only if:\n # - there are completions following the activeHelp statements, or\n # - file completion will be performed (so there will be choices after the activeHelp)\n if [ $hasActiveHelp -eq 1 ]; then\n if [ \\${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then\n __${snakeCase(getAppBin(context))}_debug \"Adding activeHelp delimiter\"\n compadd -x \"--\"\n hasActiveHelp=0\n fi\n fi\n\n if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then\n __${snakeCase(getAppBin(context))}_debug \"Activating nospace.\"\n noSpace=\"-S ''\"\n fi\n\n if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then\n __${snakeCase(getAppBin(context))}_debug \"Activating keep order.\"\n keepOrder=\"-V\"\n fi\n\n if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then\n # File extension filtering\n local filteringCmd\n filteringCmd='_files'\n for filter in \\${completions[@]}; do\n if [ \\${filter[1]} != '*' ]; then\n # zsh requires a glob pattern to do file filtering\n filter=\"\\\\*.$filter\"\n fi\n filteringCmd+=\" -g $filter\"\n done\n filteringCmd+=\" \\${flagPrefix}\"\n\n __${snakeCase(getAppBin(context))}_debug \"File filtering command: $filteringCmd\"\n _arguments '*:filename:'\"$filteringCmd\"\n elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then\n # File completion for directories only\n local subdir\n subdir=\"\\${completions[1]}\"\n if [ -n \"$subdir\" ]; then\n __${snakeCase(getAppBin(context))}_debug \"Listing directories in $subdir\"\n pushd \"\\${subdir}\" >/dev/null 2>&1\n else\n __${snakeCase(getAppBin(context))}_debug \"Listing directories in .\"\n fi\n\n local result\n _arguments '*:dirname:_files -/'\" \\${flagPrefix}\"\n result=$?\n if [ -n \"$subdir\" ]; then\n popd >/dev/null 2>&1\n fi\n return $result\n else\n __${snakeCase(getAppBin(context))}_debug \"Calling _describe\"\n if eval _describe $keepOrder \"completions\" completions -Q \\${flagPrefix} \\${noSpace}; then\n __${snakeCase(getAppBin(context))}_debug \"_describe found some completions\"\n\n # Return the success of having called _describe\n return 0\n else\n __${snakeCase(getAppBin(context))}_debug \"_describe did not find completions.\"\n __${snakeCase(getAppBin(context))}_debug \"Checking if we should do file completion.\"\n if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then\n __${snakeCase(getAppBin(context))}_debug \"deactivating file completion\"\n\n # Return 0 to indicate completion is finished and prevent zsh from\n # trying other completion algorithms (which could cause hanging).\n # We use NoFileComp directive to explicitly disable file completion.\n return 0\n else\n # Perform file completion\n __${snakeCase(getAppBin(context))}_debug \"Activating file completion\"\n\n # We must return the result of this command, so it must be the\n # last command, or else we must store its result to return it.\n _arguments '*:filename:_files'\" \\${flagPrefix}\"\n fi\n fi\n fi\n}\n\n# don't run the completion function when being sourced or eval-ed\nif [ \"\\${funcstack[1]}\" = \"_${snakeCase(getAppBin(context))}\" ]; then\n _${snakeCase(getAppBin(context))}\nfi\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 ? \"~/.zshrc\" : 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)} Zsh 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.zsh\" : options.script;\n await writeFile(outputPath, stripAnsi(completions));\n\n success(\\`${getAppTitle(context)} Zsh 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,wBAAwB;CACjC,MAAQ,UAAU,eAAwC;AAC1D,QAAS,gBAAkB,gBAAa;EACxC,IAAQ,OAAC;AACH,UAAO,UAAU,QAAE,WAAiB,eAAQ,OAAA,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