@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.
- package/README.md +1 -1
- package/dist/components/bash-config-command.cjs +132 -0
- package/dist/components/bash-config-command.d.cts +10 -0
- package/dist/components/bash-config-command.d.cts.map +1 -0
- package/dist/components/bash-config-command.d.mts +10 -0
- package/dist/components/bash-config-command.d.mts.map +1 -0
- package/dist/components/bash-config-command.mjs +132 -0
- package/dist/components/bash-config-command.mjs.map +1 -0
- package/dist/components/bash-script-command.cjs +106 -0
- package/dist/components/bash-script-command.d.cts +10 -0
- package/dist/components/bash-script-command.d.cts.map +1 -0
- package/dist/components/bash-script-command.d.mts +10 -0
- package/dist/components/bash-script-command.d.mts.map +1 -0
- package/dist/components/bash-script-command.mjs +106 -0
- package/dist/components/bash-script-command.mjs.map +1 -0
- package/dist/components/bash-shared.cjs +172 -0
- package/dist/components/bash-shared.d.cts +10 -0
- package/dist/components/bash-shared.d.cts.map +1 -0
- package/dist/components/bash-shared.d.mts +10 -0
- package/dist/components/bash-shared.d.mts.map +1 -0
- package/dist/components/bash-shared.mjs +172 -0
- package/dist/components/bash-shared.mjs.map +1 -0
- package/dist/components/fish-config-command.cjs +132 -0
- package/dist/components/fish-config-command.d.cts +10 -0
- package/dist/components/fish-config-command.d.cts.map +1 -0
- package/dist/components/fish-config-command.d.mts +10 -0
- package/dist/components/fish-config-command.d.mts.map +1 -0
- package/dist/components/fish-config-command.mjs +132 -0
- package/dist/components/fish-config-command.mjs.map +1 -0
- package/dist/components/fish-script-command.cjs +106 -0
- package/dist/components/fish-script-command.d.cts +10 -0
- package/dist/components/fish-script-command.d.cts.map +1 -0
- package/dist/components/fish-script-command.d.mts +10 -0
- package/dist/components/fish-script-command.d.mts.map +1 -0
- package/dist/components/fish-script-command.mjs +106 -0
- package/dist/components/fish-script-command.mjs.map +1 -0
- package/dist/components/fish-shared.cjs +303 -0
- package/dist/components/fish-shared.d.cts +10 -0
- package/dist/components/fish-shared.d.cts.map +1 -0
- package/dist/components/fish-shared.d.mts +10 -0
- package/dist/components/fish-shared.d.mts.map +1 -0
- package/dist/components/fish-shared.mjs +303 -0
- package/dist/components/fish-shared.mjs.map +1 -0
- package/dist/components/index.cjs +24 -8
- package/dist/components/index.d.cts +13 -5
- package/dist/components/index.d.mts +13 -5
- package/dist/components/index.mjs +13 -5
- package/dist/components/powershell-config-command.cjs +128 -0
- package/dist/components/powershell-config-command.d.cts +7 -0
- package/dist/components/powershell-config-command.d.cts.map +1 -0
- package/dist/components/powershell-config-command.d.mts +7 -0
- package/dist/components/powershell-config-command.d.mts.map +1 -0
- package/dist/components/powershell-config-command.mjs +128 -0
- package/dist/components/powershell-config-command.mjs.map +1 -0
- package/dist/components/powershell-script-command.cjs +106 -0
- package/dist/components/powershell-script-command.d.cts +10 -0
- package/dist/components/powershell-script-command.d.cts.map +1 -0
- package/dist/components/powershell-script-command.d.mts +10 -0
- package/dist/components/powershell-script-command.d.mts.map +1 -0
- package/dist/components/powershell-script-command.mjs +106 -0
- package/dist/components/powershell-script-command.mjs.map +1 -0
- package/dist/components/powershell-shared.cjs +319 -0
- package/dist/components/powershell-shared.d.cts +10 -0
- package/dist/components/powershell-shared.d.cts.map +1 -0
- package/dist/components/powershell-shared.d.mts +10 -0
- package/dist/components/powershell-shared.d.mts.map +1 -0
- package/dist/components/{powershell-command.mjs → powershell-shared.mjs} +81 -181
- package/dist/components/powershell-shared.mjs.map +1 -0
- package/dist/components/zsh-config-command.cjs +132 -0
- package/dist/components/zsh-config-command.d.cts +10 -0
- package/dist/components/zsh-config-command.d.cts.map +1 -0
- package/dist/components/zsh-config-command.d.mts +10 -0
- package/dist/components/zsh-config-command.d.mts.map +1 -0
- package/dist/components/zsh-config-command.mjs +132 -0
- package/dist/components/zsh-config-command.mjs.map +1 -0
- package/dist/components/zsh-script-command.cjs +111 -0
- package/dist/components/zsh-script-command.d.cts +10 -0
- package/dist/components/zsh-script-command.d.cts.map +1 -0
- package/dist/components/zsh-script-command.d.mts +10 -0
- package/dist/components/zsh-script-command.d.mts.map +1 -0
- package/dist/components/zsh-script-command.mjs +111 -0
- package/dist/components/zsh-script-command.mjs.map +1 -0
- package/dist/components/zsh-shared.cjs +281 -0
- package/dist/components/zsh-shared.d.cts +10 -0
- package/dist/components/zsh-shared.d.cts.map +1 -0
- package/dist/components/zsh-shared.d.mts +10 -0
- package/dist/components/zsh-shared.d.mts.map +1 -0
- package/dist/components/zsh-shared.mjs +281 -0
- package/dist/components/zsh-shared.mjs.map +1 -0
- package/dist/helpers/complete-command.cjs +2 -7
- package/dist/helpers/complete-command.d.cts +2 -2
- package/dist/helpers/complete-command.d.cts.map +1 -1
- package/dist/helpers/complete-command.d.mts +2 -2
- package/dist/helpers/complete-command.d.mts.map +1 -1
- package/dist/helpers/complete-command.mjs +2 -7
- package/dist/helpers/complete-command.mjs.map +1 -1
- package/dist/helpers/index.cjs +1 -1
- package/dist/helpers/index.d.cts +2 -2
- package/dist/helpers/index.d.mts +2 -2
- package/dist/helpers/index.mjs +2 -2
- package/dist/index.cjs +245 -59
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +246 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +148 -37
- package/dist/components/bash-command.cjs +0 -273
- package/dist/components/bash-command.d.cts +0 -10
- package/dist/components/bash-command.d.cts.map +0 -1
- package/dist/components/bash-command.d.mts +0 -10
- package/dist/components/bash-command.d.mts.map +0 -1
- package/dist/components/bash-command.mjs +0 -273
- package/dist/components/bash-command.mjs.map +0 -1
- package/dist/components/fish-command.cjs +0 -403
- package/dist/components/fish-command.d.cts +0 -10
- package/dist/components/fish-command.d.cts.map +0 -1
- package/dist/components/fish-command.d.mts +0 -10
- package/dist/components/fish-command.d.mts.map +0 -1
- package/dist/components/fish-command.mjs +0 -403
- package/dist/components/fish-command.mjs.map +0 -1
- package/dist/components/powershell-command.cjs +0 -419
- package/dist/components/powershell-command.d.cts +0 -10
- package/dist/components/powershell-command.d.cts.map +0 -1
- package/dist/components/powershell-command.d.mts +0 -10
- package/dist/components/powershell-command.d.mts.map +0 -1
- package/dist/components/powershell-command.mjs.map +0 -1
- package/dist/components/zsh-command.cjs +0 -384
- package/dist/components/zsh-command.d.cts +0 -10
- package/dist/components/zsh-command.d.cts.map +0 -1
- package/dist/components/zsh-command.d.mts +0 -10
- package/dist/components/zsh-command.d.mts.map +0 -1
- package/dist/components/zsh-command.mjs +0 -384
- package/dist/components/zsh-command.mjs.map +0 -1
|
@@ -0,0 +1,281 @@
|
|
|
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_snake_case = require("@stryke/string-format/snake-case");
|
|
14
|
+
|
|
15
|
+
//#region src/components/zsh-shared.tsx
|
|
16
|
+
/**
|
|
17
|
+
* The Zsh Completions generation for the Shell Shock project.
|
|
18
|
+
*/
|
|
19
|
+
function ZshCompletionsShared() {
|
|
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_snake_case.snakeCase)(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", "zsh", "shared.ts");
|
|
26
|
+
},
|
|
27
|
+
builtinImports: { console: ["colors"] },
|
|
28
|
+
get children() {
|
|
29
|
+
return [
|
|
30
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
31
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
32
|
+
"const": true,
|
|
33
|
+
"export": true,
|
|
34
|
+
name: "SHELL_COMPLETIONS",
|
|
35
|
+
get initializer() {
|
|
36
|
+
return _alloy_js_core.code` \`__${name.value}_debug() {
|
|
37
|
+
local file="$BASH_COMP_DEBUG_FILE"
|
|
38
|
+
if [[ -n \\\${file} ]]; then
|
|
39
|
+
echo "$*" >> "\\\${file}"
|
|
40
|
+
fi
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_${name.value}() {
|
|
44
|
+
local shellCompDirectiveError=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveError}
|
|
45
|
+
local shellCompDirectiveNoSpace=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveNoSpace}
|
|
46
|
+
local shellCompDirectiveNoFileComp=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveNoFileComp}
|
|
47
|
+
local shellCompDirectiveFilterFileExt=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveFilterFileExt}
|
|
48
|
+
local shellCompDirectiveFilterDirs=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveFilterDirs}
|
|
49
|
+
local shellCompDirectiveKeepOrder=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveKeepOrder}
|
|
50
|
+
|
|
51
|
+
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
|
|
52
|
+
local -a completions
|
|
53
|
+
|
|
54
|
+
__${name.value}_debug "\\n========= starting completion logic =========="
|
|
55
|
+
__${name.value}_debug "CURRENT: \\\${CURRENT}, words[*]: \\\${words[*]}"
|
|
56
|
+
|
|
57
|
+
# The user could have moved the cursor backwards on the command-line.
|
|
58
|
+
# We need to trigger completion from the $CURRENT location, so we need
|
|
59
|
+
# to truncate the command-line ($words) up to the $CURRENT location.
|
|
60
|
+
# (We cannot use $CURSOR as its value does not work when a command is an alias.)
|
|
61
|
+
words=( "\\\${=words[1,CURRENT]}" )
|
|
62
|
+
__${name.value}_debug "Truncated words[*]: \\\${words[*]},"
|
|
63
|
+
|
|
64
|
+
lastParam=\\\${words[-1]}
|
|
65
|
+
lastChar=\\\${lastParam[-1]}
|
|
66
|
+
__${name.value}_debug "lastParam: \\\${lastParam}, lastChar: \\\${lastChar}"
|
|
67
|
+
# For zsh, when completing a flag with an = (e.g., ${bin.value} -n=<TAB>)
|
|
68
|
+
# completions must be prefixed with the flag
|
|
69
|
+
setopt local_options BASH_REMATCH
|
|
70
|
+
if [[ "\\\${lastParam}" =~ '-.*=' ]]; then
|
|
71
|
+
# We are dealing with a flag with an =
|
|
72
|
+
flagPrefix="-P \\\${BASH_REMATCH}"
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
# Prepare the command to obtain completions, ensuring arguments are quoted for eval
|
|
76
|
+
local -a args_to_quote=("\\\${(@)words[2,-1]}")
|
|
77
|
+
if [ "\\\${lastChar}" = "" ]; then
|
|
78
|
+
# If the last parameter is complete (there is a space following it)
|
|
79
|
+
# We add an extra empty parameter so we can indicate this to the go completion code.
|
|
80
|
+
__${name.value}_debug "Adding extra empty parameter"
|
|
81
|
+
args_to_quote+=("")
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
# Use Zsh's (q) flag to quote each argument safely for eval
|
|
85
|
+
local quoted_args=("\\\${(@q)args_to_quote}")
|
|
86
|
+
|
|
87
|
+
# Join the main command and the quoted arguments into a single string for eval
|
|
88
|
+
requestComp="${require_helpers_complete_command.EXEC_COMMAND} complete -- \\\${quoted_args[*]}"
|
|
89
|
+
|
|
90
|
+
__${name.value}_debug "About to call: eval \\\${requestComp}"
|
|
91
|
+
|
|
92
|
+
# Use eval to handle any environment variables and such
|
|
93
|
+
out=$(eval \\\${requestComp} 2>/dev/null)
|
|
94
|
+
__${name.value}_debug "completion output: \\\${out}"
|
|
95
|
+
|
|
96
|
+
# Extract the directive integer following a : from the last line
|
|
97
|
+
local lastLine
|
|
98
|
+
while IFS='\n' read -r line; do
|
|
99
|
+
lastLine=\\\${line}
|
|
100
|
+
done < <(printf "%s\n" "\\\${out[@]}")
|
|
101
|
+
__${name.value}_debug "last line: \\\${lastLine}"
|
|
102
|
+
|
|
103
|
+
if [ "\\\${lastLine[1]}" = : ]; then
|
|
104
|
+
directive=\\\${lastLine[2,-1]}
|
|
105
|
+
# Remove the directive including the : and the newline
|
|
106
|
+
local suffix
|
|
107
|
+
(( suffix=\\\${#lastLine}+2))
|
|
108
|
+
out=\\\${out[1,-$suffix]}
|
|
109
|
+
else
|
|
110
|
+
# There is no directive specified. Leave $out as is.
|
|
111
|
+
__${name.value}_debug "No directive found. Setting to default"
|
|
112
|
+
directive=0
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
__${name.value}_debug "directive: \\\${directive}"
|
|
116
|
+
__${name.value}_debug "completions: \\\${out}"
|
|
117
|
+
__${name.value}_debug "flagPrefix: \\\${flagPrefix}"
|
|
118
|
+
|
|
119
|
+
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
|
120
|
+
__${name.value}_debug "Completion received error. Ignoring completions."
|
|
121
|
+
return
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
local activeHelpMarker="%"
|
|
125
|
+
local endIndex=\\\${#activeHelpMarker}
|
|
126
|
+
local startIndex=$((\\\${#activeHelpMarker}+1))
|
|
127
|
+
local hasActiveHelp=0
|
|
128
|
+
while IFS='\n' read -r comp; do
|
|
129
|
+
# Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
|
|
130
|
+
if [ "\\\${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
|
|
131
|
+
__${name.value}_debug "ActiveHelp found: $comp"
|
|
132
|
+
comp="\\\${comp[$startIndex,-1]}"
|
|
133
|
+
if [ -n "$comp" ]; then
|
|
134
|
+
compadd -x "\\\${comp}"
|
|
135
|
+
__${name.value}_debug "ActiveHelp will need delimiter"
|
|
136
|
+
hasActiveHelp=1
|
|
137
|
+
fi
|
|
138
|
+
continue
|
|
139
|
+
fi
|
|
140
|
+
|
|
141
|
+
if [ -n "$comp" ]; then
|
|
142
|
+
# If requested, completions are returned with a description.
|
|
143
|
+
# The description is preceded by a TAB character.
|
|
144
|
+
# For zsh's _describe, we need to use a : instead of a TAB.
|
|
145
|
+
# We first need to escape any : as part of the completion itself.
|
|
146
|
+
comp=\\\${comp//:/\\:}
|
|
147
|
+
|
|
148
|
+
local tab="$(printf '\\t')"
|
|
149
|
+
comp=\\\${comp//$tab/:}
|
|
150
|
+
|
|
151
|
+
__${name.value}_debug "Adding completion: \\\${comp}"
|
|
152
|
+
completions+=\\\${comp}
|
|
153
|
+
lastComp=$comp
|
|
154
|
+
fi
|
|
155
|
+
done < <(printf "%s\n" "\\\${out[@]}")
|
|
156
|
+
|
|
157
|
+
# Add a delimiter after the activeHelp statements, but only if:
|
|
158
|
+
# - there are completions following the activeHelp statements, or
|
|
159
|
+
# - file completion will be performed (so there will be choices after the activeHelp)
|
|
160
|
+
if [ $hasActiveHelp -eq 1 ]; then
|
|
161
|
+
if [ \\\${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
|
|
162
|
+
__${name.value}_debug "Adding activeHelp delimiter"
|
|
163
|
+
compadd -x "--"
|
|
164
|
+
hasActiveHelp=0
|
|
165
|
+
fi
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
|
169
|
+
__${name.value}_debug "Activating nospace."
|
|
170
|
+
noSpace="-S ''"
|
|
171
|
+
fi
|
|
172
|
+
|
|
173
|
+
if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
|
|
174
|
+
__${name.value}_debug "Activating keep order."
|
|
175
|
+
keepOrder="-V"
|
|
176
|
+
fi
|
|
177
|
+
|
|
178
|
+
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
|
|
179
|
+
# File extension filtering
|
|
180
|
+
local filteringCmd
|
|
181
|
+
filteringCmd='_files'
|
|
182
|
+
for filter in \\\${completions[@]}; do
|
|
183
|
+
if [ \\\${filter[1]} != '*' ]; then
|
|
184
|
+
# zsh requires a glob pattern to do file filtering
|
|
185
|
+
filter="\\*.$filter"
|
|
186
|
+
fi
|
|
187
|
+
filteringCmd+=" -g $filter"
|
|
188
|
+
done
|
|
189
|
+
filteringCmd+=" \\\${flagPrefix}"
|
|
190
|
+
|
|
191
|
+
__${name.value}_debug "File filtering command: $filteringCmd"
|
|
192
|
+
_arguments '*:filename:'"$filteringCmd"
|
|
193
|
+
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
|
194
|
+
# File completion for directories only
|
|
195
|
+
local subdir
|
|
196
|
+
subdir="\\\${completions[1]}"
|
|
197
|
+
if [ -n "$subdir" ]; then
|
|
198
|
+
__${name.value}_debug "Listing directories in $subdir"
|
|
199
|
+
pushd "\\\${subdir}" >/dev/null 2>&1
|
|
200
|
+
else
|
|
201
|
+
__${name.value}_debug "Listing directories in ."
|
|
202
|
+
fi
|
|
203
|
+
|
|
204
|
+
local result
|
|
205
|
+
_arguments '*:dirname:_files -/'" \\\${flagPrefix}"
|
|
206
|
+
result=$?
|
|
207
|
+
if [ -n "$subdir" ]; then
|
|
208
|
+
popd >/dev/null 2>&1
|
|
209
|
+
fi
|
|
210
|
+
return $result
|
|
211
|
+
else
|
|
212
|
+
__${name.value}_debug "Calling _describe"
|
|
213
|
+
if eval _describe $keepOrder "completions" completions -Q \\\${flagPrefix} \\\${noSpace}; then
|
|
214
|
+
__${name.value}_debug "_describe found some completions"
|
|
215
|
+
|
|
216
|
+
# Return the success of having called _describe
|
|
217
|
+
return 0
|
|
218
|
+
else
|
|
219
|
+
__${name.value}_debug "_describe did not find completions."
|
|
220
|
+
__${name.value}_debug "Checking if we should do file completion."
|
|
221
|
+
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
|
222
|
+
__${name.value}_debug "deactivating file completion"
|
|
223
|
+
|
|
224
|
+
# Return 0 to indicate completion is finished and prevent zsh from
|
|
225
|
+
# trying other completion algorithms (which could cause hanging).
|
|
226
|
+
# We use NoFileComp directive to explicitly disable file completion.
|
|
227
|
+
return 0
|
|
228
|
+
else
|
|
229
|
+
# Perform file completion
|
|
230
|
+
__${name.value}_debug "Activating file completion"
|
|
231
|
+
|
|
232
|
+
# We must return the result of this command, so it must be the
|
|
233
|
+
# last command, or else we must store its result to return it.
|
|
234
|
+
_arguments '*:filename:_files'" \\\${flagPrefix}"
|
|
235
|
+
fi
|
|
236
|
+
fi
|
|
237
|
+
fi
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
# don't run the completion function when being sourced or eval-ed
|
|
241
|
+
if [ "\\\${funcstack[1]}" = "_${name.value}" ]; then
|
|
242
|
+
_${name.value}
|
|
243
|
+
fi
|
|
244
|
+
\`; `;
|
|
245
|
+
}
|
|
246
|
+
}),
|
|
247
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
248
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
249
|
+
"export": true,
|
|
250
|
+
"const": true,
|
|
251
|
+
name: "SHELL_COMPLETIONS_DISPLAY",
|
|
252
|
+
initializer: _alloy_js_core.code` SHELL_COMPLETIONS.split("\\n").map(line => {
|
|
253
|
+
if (!line.trim()) {
|
|
254
|
+
return "";
|
|
255
|
+
}
|
|
256
|
+
if (line.trim().startsWith("#")) {
|
|
257
|
+
return \`\${colors.dim(line)}\`;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return colors.white(line).replaceAll(/(?<=\\\$(\\{|\\()).*(?=(\\}\\)))/g, colors.green("$&"))
|
|
261
|
+
.replaceAll(/\\".*\\"/g, colors.cyan("$&"))
|
|
262
|
+
.replaceAll(/(\\[|\\]|\\(|\\)|\\||<|>|\\$\\(|\\$?\\{|\\}|\\+|=|;|:)/g, colors.bold(colors.gray("$&")))
|
|
263
|
+
.replaceAll(/(readonly|complete)\\s+/g, colors.green("$&"))
|
|
264
|
+
.replaceAll(/(?<=(readonly|complete)\\s+)\\w/g, colors.bold(colors.greenBright("$&")))
|
|
265
|
+
.replaceAll(/local\\s+/g, colors.red("$&"))
|
|
266
|
+
.replaceAll(/(?<=local\\s+)\\w/g, colors.bold(colors.redBright("$&")))
|
|
267
|
+
.replaceAll(/(for|while)\\s+/g, colors.cyan("$&"))
|
|
268
|
+
.replaceAll(/(?<=for|while\\s+)\\w/g, colors.bold(colors.cyanBright("$&")))
|
|
269
|
+
.replaceAll(/(return|if|fi|else|elif|then|done)\\s+/g, colors.green("$&"))
|
|
270
|
+
.replaceAll(/__\\w/g, colors.bold(colors.magentaBright("$&")))
|
|
271
|
+
.replaceAll(/(?<=\\s)(-\\w|--\\w[\\w-]*)(?=\\s|$)/g, colors.bold(colors.magenta("$&")));
|
|
272
|
+
|
|
273
|
+
}).join("\\n"); `
|
|
274
|
+
})
|
|
275
|
+
];
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
exports.ZshCompletionsShared = ZshCompletionsShared;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _$_alloy_js_core0 from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
//#region src/components/zsh-shared.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Zsh Completions generation for the Shell Shock project.
|
|
6
|
+
*/
|
|
7
|
+
declare function ZshCompletionsShared(): _$_alloy_js_core0.Children;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ZshCompletionsShared };
|
|
10
|
+
//# sourceMappingURL=zsh-shared.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zsh-shared.d.cts","names":[],"sources":["../../src/components/zsh-shared.tsx"],"mappings":";;;;;;iBAiCgB,oBAAA,CAAA,GAAoB,iBAAA,CAAA,QAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _$_alloy_js_core0 from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
//#region src/components/zsh-shared.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Zsh Completions generation for the Shell Shock project.
|
|
6
|
+
*/
|
|
7
|
+
declare function ZshCompletionsShared(): _$_alloy_js_core0.Children;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ZshCompletionsShared };
|
|
10
|
+
//# sourceMappingURL=zsh-shared.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zsh-shared.d.mts","names":[],"sources":["../../src/components/zsh-shared.tsx"],"mappings":";;;;;;iBAiCgB,oBAAA,CAAA,GAAoB,iBAAA,CAAA,QAAA"}
|
|
@@ -0,0 +1,281 @@
|
|
|
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 } 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 { snakeCase } from "@stryke/string-format/snake-case";
|
|
13
|
+
|
|
14
|
+
//#region src/components/zsh-shared.tsx
|
|
15
|
+
/**
|
|
16
|
+
* The Zsh Completions generation for the Shell Shock project.
|
|
17
|
+
*/
|
|
18
|
+
function ZshCompletionsShared() {
|
|
19
|
+
const context = usePowerlines();
|
|
20
|
+
const bin = computed(() => getAppBin(context));
|
|
21
|
+
const name = computed(() => snakeCase(bin.value));
|
|
22
|
+
return createComponent(TypescriptFile, {
|
|
23
|
+
get path() {
|
|
24
|
+
return joinPaths(context.entryPath, "completions", "zsh", "shared.ts");
|
|
25
|
+
},
|
|
26
|
+
builtinImports: { console: ["colors"] },
|
|
27
|
+
get children() {
|
|
28
|
+
return [
|
|
29
|
+
createComponent(Spacing, {}),
|
|
30
|
+
createComponent(VarDeclaration, {
|
|
31
|
+
"const": true,
|
|
32
|
+
"export": true,
|
|
33
|
+
name: "SHELL_COMPLETIONS",
|
|
34
|
+
get initializer() {
|
|
35
|
+
return code` \`__${name.value}_debug() {
|
|
36
|
+
local file="$BASH_COMP_DEBUG_FILE"
|
|
37
|
+
if [[ -n \\\${file} ]]; then
|
|
38
|
+
echo "$*" >> "\\\${file}"
|
|
39
|
+
fi
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_${name.value}() {
|
|
43
|
+
local shellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}
|
|
44
|
+
local shellCompDirectiveNoSpace=${CompletionDirective.CompletionDirectiveNoSpace}
|
|
45
|
+
local shellCompDirectiveNoFileComp=${CompletionDirective.CompletionDirectiveNoFileComp}
|
|
46
|
+
local shellCompDirectiveFilterFileExt=${CompletionDirective.CompletionDirectiveFilterFileExt}
|
|
47
|
+
local shellCompDirectiveFilterDirs=${CompletionDirective.CompletionDirectiveFilterDirs}
|
|
48
|
+
local shellCompDirectiveKeepOrder=${CompletionDirective.CompletionDirectiveKeepOrder}
|
|
49
|
+
|
|
50
|
+
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
|
|
51
|
+
local -a completions
|
|
52
|
+
|
|
53
|
+
__${name.value}_debug "\\n========= starting completion logic =========="
|
|
54
|
+
__${name.value}_debug "CURRENT: \\\${CURRENT}, words[*]: \\\${words[*]}"
|
|
55
|
+
|
|
56
|
+
# The user could have moved the cursor backwards on the command-line.
|
|
57
|
+
# We need to trigger completion from the $CURRENT location, so we need
|
|
58
|
+
# to truncate the command-line ($words) up to the $CURRENT location.
|
|
59
|
+
# (We cannot use $CURSOR as its value does not work when a command is an alias.)
|
|
60
|
+
words=( "\\\${=words[1,CURRENT]}" )
|
|
61
|
+
__${name.value}_debug "Truncated words[*]: \\\${words[*]},"
|
|
62
|
+
|
|
63
|
+
lastParam=\\\${words[-1]}
|
|
64
|
+
lastChar=\\\${lastParam[-1]}
|
|
65
|
+
__${name.value}_debug "lastParam: \\\${lastParam}, lastChar: \\\${lastChar}"
|
|
66
|
+
# For zsh, when completing a flag with an = (e.g., ${bin.value} -n=<TAB>)
|
|
67
|
+
# completions must be prefixed with the flag
|
|
68
|
+
setopt local_options BASH_REMATCH
|
|
69
|
+
if [[ "\\\${lastParam}" =~ '-.*=' ]]; then
|
|
70
|
+
# We are dealing with a flag with an =
|
|
71
|
+
flagPrefix="-P \\\${BASH_REMATCH}"
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
# Prepare the command to obtain completions, ensuring arguments are quoted for eval
|
|
75
|
+
local -a args_to_quote=("\\\${(@)words[2,-1]}")
|
|
76
|
+
if [ "\\\${lastChar}" = "" ]; then
|
|
77
|
+
# If the last parameter is complete (there is a space following it)
|
|
78
|
+
# We add an extra empty parameter so we can indicate this to the go completion code.
|
|
79
|
+
__${name.value}_debug "Adding extra empty parameter"
|
|
80
|
+
args_to_quote+=("")
|
|
81
|
+
fi
|
|
82
|
+
|
|
83
|
+
# Use Zsh's (q) flag to quote each argument safely for eval
|
|
84
|
+
local quoted_args=("\\\${(@q)args_to_quote}")
|
|
85
|
+
|
|
86
|
+
# Join the main command and the quoted arguments into a single string for eval
|
|
87
|
+
requestComp="${EXEC_COMMAND} complete -- \\\${quoted_args[*]}"
|
|
88
|
+
|
|
89
|
+
__${name.value}_debug "About to call: eval \\\${requestComp}"
|
|
90
|
+
|
|
91
|
+
# Use eval to handle any environment variables and such
|
|
92
|
+
out=$(eval \\\${requestComp} 2>/dev/null)
|
|
93
|
+
__${name.value}_debug "completion output: \\\${out}"
|
|
94
|
+
|
|
95
|
+
# Extract the directive integer following a : from the last line
|
|
96
|
+
local lastLine
|
|
97
|
+
while IFS='\n' read -r line; do
|
|
98
|
+
lastLine=\\\${line}
|
|
99
|
+
done < <(printf "%s\n" "\\\${out[@]}")
|
|
100
|
+
__${name.value}_debug "last line: \\\${lastLine}"
|
|
101
|
+
|
|
102
|
+
if [ "\\\${lastLine[1]}" = : ]; then
|
|
103
|
+
directive=\\\${lastLine[2,-1]}
|
|
104
|
+
# Remove the directive including the : and the newline
|
|
105
|
+
local suffix
|
|
106
|
+
(( suffix=\\\${#lastLine}+2))
|
|
107
|
+
out=\\\${out[1,-$suffix]}
|
|
108
|
+
else
|
|
109
|
+
# There is no directive specified. Leave $out as is.
|
|
110
|
+
__${name.value}_debug "No directive found. Setting to default"
|
|
111
|
+
directive=0
|
|
112
|
+
fi
|
|
113
|
+
|
|
114
|
+
__${name.value}_debug "directive: \\\${directive}"
|
|
115
|
+
__${name.value}_debug "completions: \\\${out}"
|
|
116
|
+
__${name.value}_debug "flagPrefix: \\\${flagPrefix}"
|
|
117
|
+
|
|
118
|
+
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
|
119
|
+
__${name.value}_debug "Completion received error. Ignoring completions."
|
|
120
|
+
return
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
local activeHelpMarker="%"
|
|
124
|
+
local endIndex=\\\${#activeHelpMarker}
|
|
125
|
+
local startIndex=$((\\\${#activeHelpMarker}+1))
|
|
126
|
+
local hasActiveHelp=0
|
|
127
|
+
while IFS='\n' read -r comp; do
|
|
128
|
+
# Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
|
|
129
|
+
if [ "\\\${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
|
|
130
|
+
__${name.value}_debug "ActiveHelp found: $comp"
|
|
131
|
+
comp="\\\${comp[$startIndex,-1]}"
|
|
132
|
+
if [ -n "$comp" ]; then
|
|
133
|
+
compadd -x "\\\${comp}"
|
|
134
|
+
__${name.value}_debug "ActiveHelp will need delimiter"
|
|
135
|
+
hasActiveHelp=1
|
|
136
|
+
fi
|
|
137
|
+
continue
|
|
138
|
+
fi
|
|
139
|
+
|
|
140
|
+
if [ -n "$comp" ]; then
|
|
141
|
+
# If requested, completions are returned with a description.
|
|
142
|
+
# The description is preceded by a TAB character.
|
|
143
|
+
# For zsh's _describe, we need to use a : instead of a TAB.
|
|
144
|
+
# We first need to escape any : as part of the completion itself.
|
|
145
|
+
comp=\\\${comp//:/\\:}
|
|
146
|
+
|
|
147
|
+
local tab="$(printf '\\t')"
|
|
148
|
+
comp=\\\${comp//$tab/:}
|
|
149
|
+
|
|
150
|
+
__${name.value}_debug "Adding completion: \\\${comp}"
|
|
151
|
+
completions+=\\\${comp}
|
|
152
|
+
lastComp=$comp
|
|
153
|
+
fi
|
|
154
|
+
done < <(printf "%s\n" "\\\${out[@]}")
|
|
155
|
+
|
|
156
|
+
# Add a delimiter after the activeHelp statements, but only if:
|
|
157
|
+
# - there are completions following the activeHelp statements, or
|
|
158
|
+
# - file completion will be performed (so there will be choices after the activeHelp)
|
|
159
|
+
if [ $hasActiveHelp -eq 1 ]; then
|
|
160
|
+
if [ \\\${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
|
|
161
|
+
__${name.value}_debug "Adding activeHelp delimiter"
|
|
162
|
+
compadd -x "--"
|
|
163
|
+
hasActiveHelp=0
|
|
164
|
+
fi
|
|
165
|
+
fi
|
|
166
|
+
|
|
167
|
+
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
|
168
|
+
__${name.value}_debug "Activating nospace."
|
|
169
|
+
noSpace="-S ''"
|
|
170
|
+
fi
|
|
171
|
+
|
|
172
|
+
if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
|
|
173
|
+
__${name.value}_debug "Activating keep order."
|
|
174
|
+
keepOrder="-V"
|
|
175
|
+
fi
|
|
176
|
+
|
|
177
|
+
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
|
|
178
|
+
# File extension filtering
|
|
179
|
+
local filteringCmd
|
|
180
|
+
filteringCmd='_files'
|
|
181
|
+
for filter in \\\${completions[@]}; do
|
|
182
|
+
if [ \\\${filter[1]} != '*' ]; then
|
|
183
|
+
# zsh requires a glob pattern to do file filtering
|
|
184
|
+
filter="\\*.$filter"
|
|
185
|
+
fi
|
|
186
|
+
filteringCmd+=" -g $filter"
|
|
187
|
+
done
|
|
188
|
+
filteringCmd+=" \\\${flagPrefix}"
|
|
189
|
+
|
|
190
|
+
__${name.value}_debug "File filtering command: $filteringCmd"
|
|
191
|
+
_arguments '*:filename:'"$filteringCmd"
|
|
192
|
+
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
|
193
|
+
# File completion for directories only
|
|
194
|
+
local subdir
|
|
195
|
+
subdir="\\\${completions[1]}"
|
|
196
|
+
if [ -n "$subdir" ]; then
|
|
197
|
+
__${name.value}_debug "Listing directories in $subdir"
|
|
198
|
+
pushd "\\\${subdir}" >/dev/null 2>&1
|
|
199
|
+
else
|
|
200
|
+
__${name.value}_debug "Listing directories in ."
|
|
201
|
+
fi
|
|
202
|
+
|
|
203
|
+
local result
|
|
204
|
+
_arguments '*:dirname:_files -/'" \\\${flagPrefix}"
|
|
205
|
+
result=$?
|
|
206
|
+
if [ -n "$subdir" ]; then
|
|
207
|
+
popd >/dev/null 2>&1
|
|
208
|
+
fi
|
|
209
|
+
return $result
|
|
210
|
+
else
|
|
211
|
+
__${name.value}_debug "Calling _describe"
|
|
212
|
+
if eval _describe $keepOrder "completions" completions -Q \\\${flagPrefix} \\\${noSpace}; then
|
|
213
|
+
__${name.value}_debug "_describe found some completions"
|
|
214
|
+
|
|
215
|
+
# Return the success of having called _describe
|
|
216
|
+
return 0
|
|
217
|
+
else
|
|
218
|
+
__${name.value}_debug "_describe did not find completions."
|
|
219
|
+
__${name.value}_debug "Checking if we should do file completion."
|
|
220
|
+
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
|
221
|
+
__${name.value}_debug "deactivating file completion"
|
|
222
|
+
|
|
223
|
+
# Return 0 to indicate completion is finished and prevent zsh from
|
|
224
|
+
# trying other completion algorithms (which could cause hanging).
|
|
225
|
+
# We use NoFileComp directive to explicitly disable file completion.
|
|
226
|
+
return 0
|
|
227
|
+
else
|
|
228
|
+
# Perform file completion
|
|
229
|
+
__${name.value}_debug "Activating file completion"
|
|
230
|
+
|
|
231
|
+
# We must return the result of this command, so it must be the
|
|
232
|
+
# last command, or else we must store its result to return it.
|
|
233
|
+
_arguments '*:filename:_files'" \\\${flagPrefix}"
|
|
234
|
+
fi
|
|
235
|
+
fi
|
|
236
|
+
fi
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
# don't run the completion function when being sourced or eval-ed
|
|
240
|
+
if [ "\\\${funcstack[1]}" = "_${name.value}" ]; then
|
|
241
|
+
_${name.value}
|
|
242
|
+
fi
|
|
243
|
+
\`; `;
|
|
244
|
+
}
|
|
245
|
+
}),
|
|
246
|
+
createComponent(Spacing, {}),
|
|
247
|
+
createComponent(VarDeclaration, {
|
|
248
|
+
"export": true,
|
|
249
|
+
"const": true,
|
|
250
|
+
name: "SHELL_COMPLETIONS_DISPLAY",
|
|
251
|
+
initializer: code` SHELL_COMPLETIONS.split("\\n").map(line => {
|
|
252
|
+
if (!line.trim()) {
|
|
253
|
+
return "";
|
|
254
|
+
}
|
|
255
|
+
if (line.trim().startsWith("#")) {
|
|
256
|
+
return \`\${colors.dim(line)}\`;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return colors.white(line).replaceAll(/(?<=\\\$(\\{|\\()).*(?=(\\}\\)))/g, colors.green("$&"))
|
|
260
|
+
.replaceAll(/\\".*\\"/g, colors.cyan("$&"))
|
|
261
|
+
.replaceAll(/(\\[|\\]|\\(|\\)|\\||<|>|\\$\\(|\\$?\\{|\\}|\\+|=|;|:)/g, colors.bold(colors.gray("$&")))
|
|
262
|
+
.replaceAll(/(readonly|complete)\\s+/g, colors.green("$&"))
|
|
263
|
+
.replaceAll(/(?<=(readonly|complete)\\s+)\\w/g, colors.bold(colors.greenBright("$&")))
|
|
264
|
+
.replaceAll(/local\\s+/g, colors.red("$&"))
|
|
265
|
+
.replaceAll(/(?<=local\\s+)\\w/g, colors.bold(colors.redBright("$&")))
|
|
266
|
+
.replaceAll(/(for|while)\\s+/g, colors.cyan("$&"))
|
|
267
|
+
.replaceAll(/(?<=for|while\\s+)\\w/g, colors.bold(colors.cyanBright("$&")))
|
|
268
|
+
.replaceAll(/(return|if|fi|else|elif|then|done)\\s+/g, colors.green("$&"))
|
|
269
|
+
.replaceAll(/__\\w/g, colors.bold(colors.magentaBright("$&")))
|
|
270
|
+
.replaceAll(/(?<=\\s)(-\\w|--\\w[\\w-]*)(?=\\s|$)/g, colors.bold(colors.magenta("$&")));
|
|
271
|
+
|
|
272
|
+
}).join("\\n"); `
|
|
273
|
+
})
|
|
274
|
+
];
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
//#endregion
|
|
280
|
+
export { ZshCompletionsShared };
|
|
281
|
+
//# sourceMappingURL=zsh-shared.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zsh-shared.mjs","names":[],"sources":["../../src/components/zsh-shared.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 { VarDeclaration } from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport { TypescriptFile } from \"@powerlines/plugin-alloy/typescript\";\nimport { getAppBin } 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 Zsh Completions generation for the Shell Shock project.\n */\nexport function ZshCompletionsShared() {\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\", \"zsh\", \"shared.ts\")}\n builtinImports={{\n console: [\"colors\"]\n }}>\n <Spacing />\n <VarDeclaration\n const\n export\n name=\"SHELL_COMPLETIONS\"\n initializer={code` \\`__${name.value}_debug() {\n local file=\"$BASH_COMP_DEBUG_FILE\"\n if [[ -n \\\\\\${file} ]]; then\n echo \"$*\" >> \"\\\\\\${file}\"\n fi\n}\n\n_${name.value}() {\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 __${name.value}_debug \"\\\\n========= starting completion logic ==========\"\n __${name.value}_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 __${name.value}_debug \"Truncated words[*]: \\\\\\${words[*]},\"\n\n lastParam=\\\\\\${words[-1]}\n lastChar=\\\\\\${lastParam[-1]}\n __${name.value}_debug \"lastParam: \\\\\\${lastParam}, lastChar: \\\\\\${lastChar}\"\n # For zsh, when completing a flag with an = (e.g., ${bin.value} -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 __${name.value}_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_COMMAND} complete -- \\\\\\${quoted_args[*]}\"\n\n __${name.value}_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 __${name.value}_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 __${name.value}_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 __${name.value}_debug \"No directive found. Setting to default\"\n directive=0\n fi\n\n __${name.value}_debug \"directive: \\\\\\${directive}\"\n __${name.value}_debug \"completions: \\\\\\${out}\"\n __${name.value}_debug \"flagPrefix: \\\\\\${flagPrefix}\"\n\n if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then\n __${name.value}_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 __${name.value}_debug \"ActiveHelp found: $comp\"\n comp=\"\\\\\\${comp[$startIndex,-1]}\"\n if [ -n \"$comp\" ]; then\n compadd -x \"\\\\\\${comp}\"\n __${name.value}_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 __${name.value}_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 __${name.value}_debug \"Adding activeHelp delimiter\"\n compadd -x \"--\"\n hasActiveHelp=0\n fi\n fi\n\n if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then\n __${name.value}_debug \"Activating nospace.\"\n noSpace=\"-S ''\"\n fi\n\n if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then\n __${name.value}_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 __${name.value}_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 __${name.value}_debug \"Listing directories in $subdir\"\n pushd \"\\\\\\${subdir}\" >/dev/null 2>&1\n else\n __${name.value}_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 __${name.value}_debug \"Calling _describe\"\n if eval _describe $keepOrder \"completions\" completions -Q \\\\\\${flagPrefix} \\\\\\${noSpace}; then\n __${name.value}_debug \"_describe found some completions\"\n\n # Return the success of having called _describe\n return 0\n else\n __${name.value}_debug \"_describe did not find completions.\"\n __${name.value}_debug \"Checking if we should do file completion.\"\n if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then\n __${name.value}_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 __${name.value}_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]}\" = \"_${name.value}\" ]; then\n _${name.value}\nfi\n\\`; `}\n />\n <Spacing />\n <VarDeclaration\n export\n const\n name=\"SHELL_COMPLETIONS_DISPLAY\"\n initializer={code` SHELL_COMPLETIONS.split(\"\\\\n\").map(line => {\n if (!line.trim()) {\n return \"\";\n }\n if (line.trim().startsWith(\"#\")) {\n return \\`\\${colors.dim(line)}\\`;\n }\n\n return colors.white(line).replaceAll(/(?<=\\\\\\$(\\\\{|\\\\()).*(?=(\\\\}\\\\)))/g, colors.green(\"$&\"))\n .replaceAll(/\\\\\".*\\\\\"/g, colors.cyan(\"$&\"))\n .replaceAll(/(\\\\[|\\\\]|\\\\(|\\\\)|\\\\||<|>|\\\\$\\\\(|\\\\$?\\\\{|\\\\}|\\\\+|=|;|:)/g, colors.bold(colors.gray(\"$&\")))\n .replaceAll(/(readonly|complete)\\\\s+/g, colors.green(\"$&\"))\n .replaceAll(/(?<=(readonly|complete)\\\\s+)\\\\w/g, colors.bold(colors.greenBright(\"$&\")))\n .replaceAll(/local\\\\s+/g, colors.red(\"$&\"))\n .replaceAll(/(?<=local\\\\s+)\\\\w/g, colors.bold(colors.redBright(\"$&\")))\n .replaceAll(/(for|while)\\\\s+/g, colors.cyan(\"$&\"))\n .replaceAll(/(?<=for|while\\\\s+)\\\\w/g, colors.bold(colors.cyanBright(\"$&\")))\n .replaceAll(/(return|if|fi|else|elif|then|done)\\\\s+/g, colors.green(\"$&\"))\n .replaceAll(/__\\\\w/g, colors.bold(colors.magentaBright(\"$&\")))\n .replaceAll(/(?<=\\\\s)(-\\\\w|--\\\\w[\\\\w-]*)(?=\\\\s|$)/g, colors.bold(colors.magenta(\"$&\")));\n\n }).join(\"\\\\n\"); `}\n />\n </TypescriptFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,SAAgB,uBAAgB;;CAE9B,MAAM,MAAM,eAAe,UAAU,QAAQ,CAAC;CAC9C,MAAM,OAAO,eAAe,UAAU,IAAI,MAAM,CAAC;;EAEjD,IAAM,OAAC;AACJ,UAAA,UAAA,QAAA,WAAA,eAAA,OAAA,YAAA;;EAED,gBAAgB,EACd,SAAS,CAAC,SAAS,EACpB;EACD,IAAG,WAAS;AACV,UAAC;IAAA,gBAAA,SAAA,EAAA,CAAA;IAAA,gBAAA,gBAAA;KACC,SAAA;KACA,UAAA;KACA,MAAM;KACN,IAAA,cAAkB;AAChB,aAAO,IAAA,QAAA,KAAA,MAAoB;;;;;;;GAOlC,KAAC,MAAM;oCACgB,oBAAA,yBAAA;sCACtB,oBAAA,2BAAA;yCACiC,oBAAA,8BAAA;4CACX,oBAAA,iCAAA;yCACtB,oBAAA,8BAAA;wCACoC,oBAAA,6BAAA;;;;;QAKpC,KAAA,MAAA;QACA,KAAM,MAAA;;;;;;;QAON,KAAM,MAAS;;;;QAIX,KAAK,MAAM;;;;;;;;;;;;;;YAcR,KAAA,MAAA;;;;;;;;mBAQI,aAAiB;;QAExB,KAAK,MAAM;;;;;;;;;;;QAWX,KAAK,MAAM;;;;;;;;;;YAUP,KAAC,MAAU;;;;QAIf,KAAA,MAAW;QACX,KAAE,MAAO;QACT,KAAK,MAAC;;;YAGV,KAAA,MAAA;;;;;;;;;;;gBAWY,KAAC,MAAM;;;;oBAIb,KAAA,MAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA2Bb,KAAK,MAAM;;;;;;;YAOnB,KAAS,MAAC;;;;;YAKN,KAAA,MAAW;;;;;;;;;;;;;;;;;YAiBf,KAAM,MAAA;;;;;;;gBAOF,KAAA,MAAe;;;;;;;;;;;;;;YAcf,KAAI,MAAK;;;;;;;gBAOL,KAAG,MAAQ;gBACnB,KAAA,MAAA;;oBAEJ,KAAA,MAAA;;;;;;;;oBAQgB,KAAC,MAAM;;;;;;;;;;;gCAWI,KAAM,MAAE;;;;;KAKhC,CAAC;IAAE,gBAAE,SAAA,EAAA,CAAA;IAAA,gBAAA,gBAAA;KACJ,UAAA;KACJ,SAAA;KACJ,MAAA;;;;;;;;;;;;;;;;;;;;;;;KAuBO,CAAC;IAAC;;EAEN,CAAC"}
|
|
@@ -4,12 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
function quoteIfNeeded(path) {
|
|
5
5
|
return path.includes(" ") ? `'${path}'` : path;
|
|
6
6
|
}
|
|
7
|
-
const
|
|
8
|
-
const processArgs = process.argv.slice(1);
|
|
9
|
-
const quotedExecPath = quoteIfNeeded(execPath);
|
|
10
|
-
const quotedProcessArgs = processArgs.map(quoteIfNeeded);
|
|
11
|
-
const quotedProcessExecArgs = process.execArgv.map(quoteIfNeeded);
|
|
12
|
-
const exec = `${quotedExecPath} ${quotedProcessExecArgs.join(" ")} ${quotedProcessArgs[0]}`;
|
|
7
|
+
const EXEC_COMMAND = `${quoteIfNeeded(process.execPath)} ${process.execArgv.map(quoteIfNeeded).join(" ")} ${process.argv.slice(1).map(quoteIfNeeded)[0]}`;
|
|
13
8
|
|
|
14
9
|
//#endregion
|
|
15
|
-
exports.
|
|
10
|
+
exports.EXEC_COMMAND = EXEC_COMMAND;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"complete-command.d.cts","names":[],"sources":["../../src/helpers/complete-command.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"complete-command.d.cts","names":[],"sources":["../../src/helpers/complete-command.ts"],"mappings":";cAsBa,YAAA"}
|