@visulima/vis 1.0.0-alpha.43 → 1.0.0-alpha.45
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/CHANGELOG.md +78 -0
- package/LICENSE.md +256 -0
- package/bin/resolve-binary.mjs +85 -0
- package/bin/vis.mjs +76 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +1 -2
- package/dist/binx.js +1 -1
- package/dist/packem_chunks/CONFIG_FILES.js +1 -1
- package/dist/packem_chunks/bloom-status.js +1 -1
- package/dist/packem_chunks/bloom-sync.js +1 -1
- package/dist/packem_chunks/catalog.js +63 -62
- package/dist/packem_chunks/cli-exec.js +1 -1
- package/dist/packem_chunks/cli-main.js +173 -973
- package/dist/packem_chunks/detect.js +1 -1
- package/dist/packem_chunks/dispatch.js +1 -1
- package/dist/packem_chunks/fix.js +1 -1
- package/dist/packem_chunks/handler.js +1 -1
- package/dist/packem_chunks/handler10.js +1 -1
- package/dist/packem_chunks/handler11.js +1 -1
- package/dist/packem_chunks/handler12.js +2 -2
- package/dist/packem_chunks/handler13.js +1 -1
- package/dist/packem_chunks/handler14.js +1 -1
- package/dist/packem_chunks/handler15.js +1 -1
- package/dist/packem_chunks/handler16.js +1 -1
- package/dist/packem_chunks/handler17.js +1 -1
- package/dist/packem_chunks/handler18.js +1 -1
- package/dist/packem_chunks/handler19.js +1 -1
- package/dist/packem_chunks/handler2.js +1 -1
- package/dist/packem_chunks/handler20.js +1 -1
- package/dist/packem_chunks/handler21.js +1 -1
- package/dist/packem_chunks/handler22.js +13 -4
- package/dist/packem_chunks/handler23.js +1 -1
- package/dist/packem_chunks/handler24.js +1 -1
- package/dist/packem_chunks/handler26.js +1 -1
- package/dist/packem_chunks/handler27.js +1 -1
- package/dist/packem_chunks/handler28.js +1 -1
- package/dist/packem_chunks/handler29.js +1 -1
- package/dist/packem_chunks/handler3.js +1 -1
- package/dist/packem_chunks/handler30.js +1 -1
- package/dist/packem_chunks/handler4.js +1 -1
- package/dist/packem_chunks/handler5.js +3 -3
- package/dist/packem_chunks/handler50.js +4 -4
- package/dist/packem_chunks/handler51.js +3 -3
- package/dist/packem_chunks/handler53.js +1 -1
- package/dist/packem_chunks/handler54.js +2 -2
- package/dist/packem_chunks/handler55.js +1 -1
- package/dist/packem_chunks/handler57.js +4 -4
- package/dist/packem_chunks/handler58.js +1 -1
- package/dist/packem_chunks/handler59.js +2 -2
- package/dist/packem_chunks/handler6.js +6 -6
- package/dist/packem_chunks/handler60.js +18 -18
- package/dist/packem_chunks/handler61.js +1 -1
- package/dist/packem_chunks/handler62.js +3 -3
- package/dist/packem_chunks/handler63.js +4 -4
- package/dist/packem_chunks/handler65.js +2 -2
- package/dist/packem_chunks/handler66.js +15 -15
- package/dist/packem_chunks/handler67.js +5 -5
- package/dist/packem_chunks/handler68.js +16 -16
- package/dist/packem_chunks/handler69.js +5 -5
- package/dist/packem_chunks/handler7.js +1 -1
- package/dist/packem_chunks/handler70.js +16 -17
- package/dist/packem_chunks/handler71.js +2 -2
- package/dist/packem_chunks/handler72.js +2 -2
- package/dist/packem_chunks/handler73.js +13 -13
- package/dist/packem_chunks/handler74.js +3 -3
- package/dist/packem_chunks/handler75.js +3 -3
- package/dist/packem_chunks/handler76.js +63 -63
- package/dist/packem_chunks/handler77.js +1 -1
- package/dist/packem_chunks/handler8.js +1 -1
- package/dist/packem_chunks/handler9.js +1 -1
- package/dist/packem_chunks/heal-accept.js +1 -1
- package/dist/packem_chunks/heal.js +1 -1
- package/dist/packem_chunks/help-command.js +1 -1
- package/dist/packem_chunks/index2.js +802 -7
- package/dist/packem_chunks/index3.js +7 -135
- package/dist/packem_chunks/index4.js +134 -73
- package/dist/packem_chunks/index5.js +74 -0
- package/dist/packem_chunks/keys-refresh.js +1 -1
- package/dist/packem_chunks/lean.js +3 -3
- package/dist/packem_chunks/list.js +1 -1
- package/dist/packem_chunks/loader.js +1 -1
- package/dist/packem_chunks/loader2.js +1 -1
- package/dist/packem_chunks/print-config.js +1 -1
- package/dist/packem_chunks/registry.js +2 -2
- package/dist/packem_chunks/shell-runner.js +1 -1
- package/dist/packem_chunks/sync.js +1 -1
- package/dist/packem_chunks/sync2.js +1 -1
- package/dist/packem_chunks/tripwire.js +2 -2
- package/dist/packem_chunks/ts-loader.js +22 -2
- package/dist/packem_chunks/verify-lockfile.js +1 -1
- package/dist/packem_chunks/version-resolver.js +2 -2
- package/dist/packem_shared/{Table-CcVkyULl-DLWu6XHL.js → Table-BGIHvenQ-D2oJtNQj.js} +1 -1
- package/dist/packem_shared/affected-shas-CCxG4tvm.js +1 -0
- package/dist/packem_shared/{ai-analysis-Co-b15d_.js → ai-analysis-rC48NLfB.js} +5 -5
- package/dist/packem_shared/{ai-fix-DnJDgPN-.js → ai-fix-D_ijV3Rn.js} +3 -3
- package/dist/packem_shared/augment-DaSS2Lgs.js +4 -0
- package/dist/packem_shared/bin-CPMo34SM.js +1 -0
- package/dist/packem_shared/{build-scripts-Doxce2VM.js → build-scripts-MTSK6TNr.js} +1 -1
- package/dist/packem_shared/{command-runtime-RiCMa2C8.js → command-runtime-3FTGuUsK.js} +1 -1
- package/dist/packem_shared/{cyclonedx-BTBzGCBW.js → cyclonedx-BeUmPgfO.js} +1 -1
- package/dist/packem_shared/{dependency-scan-DEv-scN6.js → dependency-scan-DpOFiZuI.js} +1 -1
- package/dist/packem_shared/{docker-DKlF-gk3.js → docker-CViFYtmM.js} +1 -1
- package/dist/packem_shared/{env-XJzocuUP.js → env-Ct3hMEYB.js} +2 -2
- package/dist/packem_shared/{failure-log-Sp1j-5qo.js → failure-log-Dy2G-rKi.js} +1 -1
- package/dist/packem_shared/glob-fqg4KepW-1S3z30c8.js +1 -0
- package/dist/packem_shared/index-CE6MsgcV.js +22 -0
- package/dist/packem_shared/{index-CkZnT2Fe.js → index-Cntyu-w8.js} +1 -1
- package/dist/packem_shared/{index-DJAnbLEh.js → index-XAb0QGqA.js} +1 -1
- package/dist/packem_shared/{lifecycle-C4nRsXxc.js → lifecycle-CHcFuWf_.js} +1 -1
- package/dist/packem_shared/{lockfile-DIGyLfmF.js → lockfile-C1qCKGH6.js} +1 -1
- package/dist/packem_shared/{manifests-pLwnVmCN.js → manifests-WBnsV_Eb.js} +1 -1
- package/dist/packem_shared/{min-release-age-B23Mr7NO.js → min-release-age-C71MO72F.js} +1 -1
- package/dist/packem_shared/{missing-package-json-DdMNbe_j.js → missing-package-json-CTF71tE5.js} +1 -1
- package/dist/packem_shared/{native-config-sync-4K9wWTj5.js → native-config-sync-BFDVK9LH.js} +4 -4
- package/dist/packem_shared/{osv-bloom-BsQ-aFiM.js → osv-bloom-DVMlkcAO.js} +2 -2
- package/dist/packem_shared/{packument-QjOLAMSk.js → packument-C-A3Uhhx.js} +1 -1
- package/dist/packem_shared/pm-runner-CQcraCcu.js +1 -0
- package/dist/packem_shared/{provenance-CilBg0Ee.js → provenance-R2csDSNg.js} +1 -1
- package/dist/packem_shared/readJsonSync-CvkZyKmL-ihoybKvs.js +1 -0
- package/dist/packem_shared/{registry-keys-BEavOCPz.js → registry-keys-CMnS_Qt_.js} +1 -1
- package/dist/packem_shared/{resolve-explicit-C4o8_-SE.js → resolve-explicit-C4oQMyoB.js} +1 -1
- package/dist/packem_shared/resolve-runtime-QRaQucfL.js +1 -0
- package/dist/packem_shared/run-file-DD7Ne23Z.js +1 -0
- package/dist/packem_shared/{runtime-check-0lUJvgKt.js → runtime-check-BXehSP06.js} +1 -1
- package/dist/packem_shared/{s1ngularity-DuG-LLaX.js → s1ngularity-BCDt28u0.js} +1 -1
- package/dist/packem_shared/scan-progress-YRpDs90j.js +2 -0
- package/dist/packem_shared/{selectors-UmnAuc26.js → selectors-D4iCvITE.js} +1 -1
- package/dist/packem_shared/{signatures-CYheSqd3.js → signatures-B3srzCEv.js} +1 -1
- package/dist/packem_shared/target-options-CR0OuYJr.js +1 -0
- package/dist/packem_shared/toolchain-C44mPKPu.js +5 -0
- package/dist/packem_shared/{typosquats-hCtH-23t.js → typosquats-CQz-1Y6K.js} +1 -1
- package/dist/packem_shared/use-measured-height-DHi0xOPO.js +1 -0
- package/dist/packem_shared/utils-CRueU43T.js +1 -0
- package/dist/packem_shared/verify-DStfg3nb.js +1 -0
- package/dist/packem_shared/{vis-update-app-K-qATSeh.js → vis-update-app-B3I14Vfy.js} +1 -1
- package/dist/packem_shared/{watch-Bkp_AAbc.js → watch-BXNI7dC6.js} +1 -1
- package/dist/packem_shared/{watch-loop-WE7nWIEt.js → watch-loop-JfGKIgKB.js} +1 -1
- package/dist/runtime/preload.js +1 -1
- package/index.js +52 -52
- package/package.json +18 -14
- package/dist/packem_shared/affected-shas-C1XuRlvo.js +0 -1
- package/dist/packem_shared/augment-8fIWWGSc.js +0 -3
- package/dist/packem_shared/bin-DDq2oszw.js +0 -1
- package/dist/packem_shared/glob-fqg4KepW-7Bs2kZuM.js +0 -1
- package/dist/packem_shared/index-OQZQyN5R.js +0 -19
- package/dist/packem_shared/pm-runner-CIH0wPh-.js +0 -1
- package/dist/packem_shared/readJsonSync-CvkZyKmL-CY7PZob_.js +0 -4
- package/dist/packem_shared/resolve-runtime-CJSWV-K8.js +0 -1
- package/dist/packem_shared/run-file-B4TqKa0X.js +0 -1
- package/dist/packem_shared/scan-progress-RTMsE3Z4.js +0 -2
- package/dist/packem_shared/target-options-ChWcK60i.js +0 -1
- package/dist/packem_shared/toolchain-DyCKnGch.js +0 -5
- package/dist/packem_shared/use-measured-height-BKUjhm_3.js +0 -1
- package/dist/packem_shared/utils-Cxree603.js +0 -1
- package/dist/packem_shared/verify-CVPYlUrF.js +0 -1
- package/dist/packem_shared/window-ops-DDePlWLV.js +0 -2
|
@@ -1,7 +1,802 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import{createRequire as u}from"node:module";const h=u(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,_=t=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[i,e]=p.versions.node.split(".").map(Number);if(i>22||i===22&&e>=3||i===20&&e>=16)return p.getBuiltinModule(t)}return h(t)},$=_("node:assert");function f(t,i){return`#compdef ${t}
|
|
2
|
+
compdef _${t} ${t}
|
|
3
|
+
|
|
4
|
+
# zsh completion for ${t} -*- shell-script -*-
|
|
5
|
+
|
|
6
|
+
__${t}_debug() {
|
|
7
|
+
local file="$BASH_COMP_DEBUG_FILE"
|
|
8
|
+
if [[ -n \${file} ]]; then
|
|
9
|
+
echo "$*" >> "\${file}"
|
|
10
|
+
fi
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
_${t}() {
|
|
14
|
+
local shellCompDirectiveError=${n.ShellCompDirectiveError}
|
|
15
|
+
local shellCompDirectiveNoSpace=${n.ShellCompDirectiveNoSpace}
|
|
16
|
+
local shellCompDirectiveNoFileComp=${n.ShellCompDirectiveNoFileComp}
|
|
17
|
+
local shellCompDirectiveFilterFileExt=${n.ShellCompDirectiveFilterFileExt}
|
|
18
|
+
local shellCompDirectiveFilterDirs=${n.ShellCompDirectiveFilterDirs}
|
|
19
|
+
local shellCompDirectiveKeepOrder=${n.ShellCompDirectiveKeepOrder}
|
|
20
|
+
|
|
21
|
+
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
|
|
22
|
+
local -a completions
|
|
23
|
+
|
|
24
|
+
__${t}_debug "\\n========= starting completion logic =========="
|
|
25
|
+
__${t}_debug "CURRENT: \${CURRENT}, words[*]: \${words[*]}"
|
|
26
|
+
|
|
27
|
+
# The user could have moved the cursor backwards on the command-line.
|
|
28
|
+
# We need to trigger completion from the $CURRENT location, so we need
|
|
29
|
+
# to truncate the command-line ($words) up to the $CURRENT location.
|
|
30
|
+
# (We cannot use $CURSOR as its value does not work when a command is an alias.)
|
|
31
|
+
words=( "\${=words[1,CURRENT]}" )
|
|
32
|
+
__${t}_debug "Truncated words[*]: \${words[*]},"
|
|
33
|
+
|
|
34
|
+
lastParam=\${words[-1]}
|
|
35
|
+
lastChar=\${lastParam[-1]}
|
|
36
|
+
__${t}_debug "lastParam: \${lastParam}, lastChar: \${lastChar}"
|
|
37
|
+
|
|
38
|
+
# For zsh, when completing a flag with an = (e.g., ${t} -n=<TAB>)
|
|
39
|
+
# completions must be prefixed with the flag
|
|
40
|
+
setopt local_options BASH_REMATCH
|
|
41
|
+
if [[ "\${lastParam}" =~ '-.*=' ]]; then
|
|
42
|
+
# We are dealing with a flag with an =
|
|
43
|
+
flagPrefix="-P \${BASH_REMATCH}"
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
# Prepare the command to obtain completions, ensuring arguments are quoted for eval
|
|
47
|
+
local -a args_to_quote=("\${(@)words[2,-1]}")
|
|
48
|
+
if [ "\${lastChar}" = "" ]; then
|
|
49
|
+
# If the last parameter is complete (there is a space following it)
|
|
50
|
+
# We add an extra empty parameter so we can indicate this to the go completion code.
|
|
51
|
+
__${t}_debug "Adding extra empty parameter"
|
|
52
|
+
args_to_quote+=("")
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# Use Zsh's (q) flag to quote each argument safely for eval
|
|
56
|
+
local quoted_args=("\${(@q)args_to_quote}")
|
|
57
|
+
|
|
58
|
+
# Join the main command and the quoted arguments into a single string for eval
|
|
59
|
+
requestComp="${i} complete -- \${quoted_args[*]}"
|
|
60
|
+
|
|
61
|
+
__${t}_debug "About to call: eval \${requestComp}"
|
|
62
|
+
|
|
63
|
+
# Use eval to handle any environment variables and such
|
|
64
|
+
out=$(eval \${requestComp} 2>/dev/null)
|
|
65
|
+
__${t}_debug "completion output: \${out}"
|
|
66
|
+
|
|
67
|
+
# Extract the directive integer following a : from the last line
|
|
68
|
+
local lastLine
|
|
69
|
+
while IFS='
|
|
70
|
+
' read -r line; do
|
|
71
|
+
lastLine=\${line}
|
|
72
|
+
done < <(printf "%s
|
|
73
|
+
" "\${out[@]}")
|
|
74
|
+
__${t}_debug "last line: \${lastLine}"
|
|
75
|
+
|
|
76
|
+
if [ "\${lastLine[1]}" = : ]; then
|
|
77
|
+
directive=\${lastLine[2,-1]}
|
|
78
|
+
# Remove the directive including the : and the newline
|
|
79
|
+
local suffix
|
|
80
|
+
(( suffix=\${#lastLine}+2))
|
|
81
|
+
out=\${out[1,-$suffix]}
|
|
82
|
+
else
|
|
83
|
+
# There is no directive specified. Leave $out as is.
|
|
84
|
+
__${t}_debug "No directive found. Setting to default"
|
|
85
|
+
directive=0
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
__${t}_debug "directive: \${directive}"
|
|
89
|
+
__${t}_debug "completions: \${out}"
|
|
90
|
+
__${t}_debug "flagPrefix: \${flagPrefix}"
|
|
91
|
+
|
|
92
|
+
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
|
93
|
+
__${t}_debug "Completion received error. Ignoring completions."
|
|
94
|
+
return
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
local activeHelpMarker="%"
|
|
98
|
+
local endIndex=\${#activeHelpMarker}
|
|
99
|
+
local startIndex=$((\${#activeHelpMarker}+1))
|
|
100
|
+
local hasActiveHelp=0
|
|
101
|
+
while IFS='
|
|
102
|
+
' read -r comp; do
|
|
103
|
+
# Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
|
|
104
|
+
if [ "\${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
|
|
105
|
+
__${t}_debug "ActiveHelp found: $comp"
|
|
106
|
+
comp="\${comp[$startIndex,-1]}"
|
|
107
|
+
if [ -n "$comp" ]; then
|
|
108
|
+
compadd -x "\${comp}"
|
|
109
|
+
__${t}_debug "ActiveHelp will need delimiter"
|
|
110
|
+
hasActiveHelp=1
|
|
111
|
+
fi
|
|
112
|
+
continue
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
if [ -n "$comp" ]; then
|
|
116
|
+
# If requested, completions are returned with a description.
|
|
117
|
+
# The description is preceded by a TAB character.
|
|
118
|
+
# For zsh's _describe, we need to use a : instead of a TAB.
|
|
119
|
+
# We first need to escape any : as part of the completion itself.
|
|
120
|
+
comp=\${comp//:/\\:}
|
|
121
|
+
|
|
122
|
+
local tab="$(printf '\\t')"
|
|
123
|
+
comp=\${comp//$tab/:}
|
|
124
|
+
|
|
125
|
+
__${t}_debug "Adding completion: \${comp}"
|
|
126
|
+
completions+=\${comp}
|
|
127
|
+
lastComp=$comp
|
|
128
|
+
fi
|
|
129
|
+
done < <(printf "%s
|
|
130
|
+
" "\${out[@]}")
|
|
131
|
+
|
|
132
|
+
# Add a delimiter after the activeHelp statements, but only if:
|
|
133
|
+
# - there are completions following the activeHelp statements, or
|
|
134
|
+
# - file completion will be performed (so there will be choices after the activeHelp)
|
|
135
|
+
if [ $hasActiveHelp -eq 1 ]; then
|
|
136
|
+
if [ \${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
|
|
137
|
+
__${t}_debug "Adding activeHelp delimiter"
|
|
138
|
+
compadd -x "--"
|
|
139
|
+
hasActiveHelp=0
|
|
140
|
+
fi
|
|
141
|
+
fi
|
|
142
|
+
|
|
143
|
+
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
|
144
|
+
__${t}_debug "Activating nospace."
|
|
145
|
+
noSpace="-S ''"
|
|
146
|
+
fi
|
|
147
|
+
|
|
148
|
+
if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
|
|
149
|
+
__${t}_debug "Activating keep order."
|
|
150
|
+
keepOrder="-V"
|
|
151
|
+
fi
|
|
152
|
+
|
|
153
|
+
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
|
|
154
|
+
# File extension filtering
|
|
155
|
+
local filteringCmd
|
|
156
|
+
filteringCmd='_files'
|
|
157
|
+
for filter in \${completions[@]}; do
|
|
158
|
+
if [ \${filter[1]} != '*' ]; then
|
|
159
|
+
# zsh requires a glob pattern to do file filtering
|
|
160
|
+
filter="\\*.$filter"
|
|
161
|
+
fi
|
|
162
|
+
filteringCmd+=" -g $filter"
|
|
163
|
+
done
|
|
164
|
+
filteringCmd+=" \${flagPrefix}"
|
|
165
|
+
|
|
166
|
+
__${t}_debug "File filtering command: $filteringCmd"
|
|
167
|
+
_arguments '*:filename:'"$filteringCmd"
|
|
168
|
+
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
|
169
|
+
# File completion for directories only
|
|
170
|
+
local subdir
|
|
171
|
+
subdir="\${completions[1]}"
|
|
172
|
+
if [ -n "$subdir" ]; then
|
|
173
|
+
__${t}_debug "Listing directories in $subdir"
|
|
174
|
+
pushd "\${subdir}" >/dev/null 2>&1
|
|
175
|
+
else
|
|
176
|
+
__${t}_debug "Listing directories in ."
|
|
177
|
+
fi
|
|
178
|
+
|
|
179
|
+
local result
|
|
180
|
+
_arguments '*:dirname:_files -/'" \${flagPrefix}"
|
|
181
|
+
result=$?
|
|
182
|
+
if [ -n "$subdir" ]; then
|
|
183
|
+
popd >/dev/null 2>&1
|
|
184
|
+
fi
|
|
185
|
+
return $result
|
|
186
|
+
else
|
|
187
|
+
__${t}_debug "Calling _describe"
|
|
188
|
+
if eval _describe $keepOrder "completions" completions -Q \${flagPrefix} \${noSpace}; then
|
|
189
|
+
__${t}_debug "_describe found some completions"
|
|
190
|
+
|
|
191
|
+
# Return the success of having called _describe
|
|
192
|
+
return 0
|
|
193
|
+
else
|
|
194
|
+
__${t}_debug "_describe did not find completions."
|
|
195
|
+
__${t}_debug "Checking if we should do file completion."
|
|
196
|
+
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
|
197
|
+
__${t}_debug "deactivating file completion"
|
|
198
|
+
|
|
199
|
+
# Return 0 to indicate completion is finished and prevent zsh from
|
|
200
|
+
# trying other completion algorithms (which could cause hanging).
|
|
201
|
+
# We use NoFileComp directive to explicitly disable file completion.
|
|
202
|
+
return 0
|
|
203
|
+
else
|
|
204
|
+
# Perform file completion
|
|
205
|
+
__${t}_debug "Activating file completion"
|
|
206
|
+
|
|
207
|
+
# We must return the result of this command, so it must be the
|
|
208
|
+
# last command, or else we must store its result to return it.
|
|
209
|
+
_arguments '*:filename:_files'" \${flagPrefix}"
|
|
210
|
+
fi
|
|
211
|
+
fi
|
|
212
|
+
fi
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
# don't run the completion function when being sourced or eval-ed
|
|
216
|
+
if [ "\${funcstack[1]}" = "_${t}" ]; then
|
|
217
|
+
_${t}
|
|
218
|
+
fi
|
|
219
|
+
`}function g(t,i){let e=t.replace(/[-:]/g,"_");return`# bash completion for ${t}
|
|
220
|
+
|
|
221
|
+
# Define shell completion directives
|
|
222
|
+
readonly ShellCompDirectiveError=${n.ShellCompDirectiveError}
|
|
223
|
+
readonly ShellCompDirectiveNoSpace=${n.ShellCompDirectiveNoSpace}
|
|
224
|
+
readonly ShellCompDirectiveNoFileComp=${n.ShellCompDirectiveNoFileComp}
|
|
225
|
+
readonly ShellCompDirectiveFilterFileExt=${n.ShellCompDirectiveFilterFileExt}
|
|
226
|
+
readonly ShellCompDirectiveFilterDirs=${n.ShellCompDirectiveFilterDirs}
|
|
227
|
+
readonly ShellCompDirectiveKeepOrder=${n.ShellCompDirectiveKeepOrder}
|
|
228
|
+
|
|
229
|
+
# Function to debug completion
|
|
230
|
+
__${e}_debug() {
|
|
231
|
+
if [[ -n \${BASH_COMP_DEBUG_FILE:-} ]]; then
|
|
232
|
+
echo "$*" >> "\${BASH_COMP_DEBUG_FILE}"
|
|
233
|
+
fi
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
# Function to handle completions
|
|
237
|
+
__${e}_complete() {
|
|
238
|
+
local cur prev words cword
|
|
239
|
+
_get_comp_words_by_ref -n "=:" cur prev words cword
|
|
240
|
+
|
|
241
|
+
local requestComp out directive
|
|
242
|
+
|
|
243
|
+
# Build the command to get completions
|
|
244
|
+
requestComp="${i} complete -- \${words[@]:1}"
|
|
245
|
+
|
|
246
|
+
# Add an empty parameter if the last parameter is complete
|
|
247
|
+
if [[ -z "$cur" ]]; then
|
|
248
|
+
requestComp="$requestComp ''"
|
|
249
|
+
fi
|
|
250
|
+
|
|
251
|
+
# Get completions from the program
|
|
252
|
+
out=$(eval "$requestComp" 2>/dev/null)
|
|
253
|
+
|
|
254
|
+
# Extract directive if present
|
|
255
|
+
directive=0
|
|
256
|
+
if [[ "$out" == *:* ]]; then
|
|
257
|
+
directive=\${out##*:}
|
|
258
|
+
out=\${out%:*}
|
|
259
|
+
fi
|
|
260
|
+
|
|
261
|
+
# Process completions based on directive
|
|
262
|
+
if [[ $((directive & $ShellCompDirectiveError)) -ne 0 ]]; then
|
|
263
|
+
# Error, no completion
|
|
264
|
+
return
|
|
265
|
+
fi
|
|
266
|
+
|
|
267
|
+
# Apply directives
|
|
268
|
+
if [[ $((directive & $ShellCompDirectiveNoSpace)) -ne 0 ]]; then
|
|
269
|
+
compopt -o nospace
|
|
270
|
+
fi
|
|
271
|
+
if [[ $((directive & $ShellCompDirectiveKeepOrder)) -ne 0 ]]; then
|
|
272
|
+
compopt -o nosort
|
|
273
|
+
fi
|
|
274
|
+
if [[ $((directive & $ShellCompDirectiveNoFileComp)) -ne 0 ]]; then
|
|
275
|
+
compopt +o default
|
|
276
|
+
fi
|
|
277
|
+
|
|
278
|
+
# Handle file extension filtering
|
|
279
|
+
if [[ $((directive & $ShellCompDirectiveFilterFileExt)) -ne 0 ]]; then
|
|
280
|
+
local filter=""
|
|
281
|
+
for ext in $out; do
|
|
282
|
+
filter="$filter|$ext"
|
|
283
|
+
done
|
|
284
|
+
filter="\\.($filter)"
|
|
285
|
+
compopt -o filenames
|
|
286
|
+
COMPREPLY=( $(compgen -f -X "!$filter" -- "$cur") )
|
|
287
|
+
return
|
|
288
|
+
fi
|
|
289
|
+
|
|
290
|
+
# Handle directory filtering
|
|
291
|
+
if [[ $((directive & $ShellCompDirectiveFilterDirs)) -ne 0 ]]; then
|
|
292
|
+
compopt -o dirnames
|
|
293
|
+
COMPREPLY=( $(compgen -d -- "$cur") )
|
|
294
|
+
return
|
|
295
|
+
fi
|
|
296
|
+
|
|
297
|
+
# Process completions
|
|
298
|
+
local IFS=$'\\n'
|
|
299
|
+
local tab=$(printf '\\t')
|
|
300
|
+
|
|
301
|
+
# Parse completions with descriptions
|
|
302
|
+
local completions=()
|
|
303
|
+
while read -r comp; do
|
|
304
|
+
if [[ "$comp" == *$tab* ]]; then
|
|
305
|
+
# Split completion and description
|
|
306
|
+
local value=\${comp%%$tab*}
|
|
307
|
+
local desc=\${comp#*$tab}
|
|
308
|
+
completions+=("$value")
|
|
309
|
+
else
|
|
310
|
+
completions+=("$comp")
|
|
311
|
+
fi
|
|
312
|
+
done <<< "$out"
|
|
313
|
+
|
|
314
|
+
# Return completions
|
|
315
|
+
COMPREPLY=( $(compgen -W "\${completions[*]}" -- "$cur") )
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
# Register completion function
|
|
319
|
+
complete -F __${e}_complete ${t}
|
|
320
|
+
`}function v(t,i){let e=t.replace(/[-:]/g,"_"),o=n.ShellCompDirectiveError,l=n.ShellCompDirectiveNoSpace,r=n.ShellCompDirectiveNoFileComp,s=n.ShellCompDirectiveFilterFileExt,a=n.ShellCompDirectiveFilterDirs;return`# fish completion for ${t} -*- shell-script -*-
|
|
321
|
+
|
|
322
|
+
function __${e}_debug
|
|
323
|
+
set -l file "$BASH_COMP_DEBUG_FILE"
|
|
324
|
+
if test -n "$file"
|
|
325
|
+
echo "$argv" >> $file
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
function __${e}_perform_completion
|
|
330
|
+
__${e}_debug "Starting __${e}_perform_completion"
|
|
331
|
+
|
|
332
|
+
# Extract all args except the last one
|
|
333
|
+
set -l args (commandline -opc)
|
|
334
|
+
# Extract the last arg and escape it in case it is a space or wildcard
|
|
335
|
+
set -l lastArg (string escape -- (commandline -ct))
|
|
336
|
+
|
|
337
|
+
__${e}_debug "args: $args"
|
|
338
|
+
__${e}_debug "last arg: $lastArg"
|
|
339
|
+
|
|
340
|
+
# Build the completion request command
|
|
341
|
+
set -l requestComp "${i} complete -- (string join ' ' -- (string escape -- $args[2..-1])) $lastArg"
|
|
342
|
+
|
|
343
|
+
__${e}_debug "Calling $requestComp"
|
|
344
|
+
set -l results (eval $requestComp 2> /dev/null)
|
|
345
|
+
|
|
346
|
+
# Some programs may output extra empty lines after the directive.
|
|
347
|
+
# Let's ignore them or else it will break completion.
|
|
348
|
+
# Ref: https://github.com/spf13/cobra/issues/1279
|
|
349
|
+
for line in $results[-1..1]
|
|
350
|
+
if test (string trim -- $line) = ""
|
|
351
|
+
# Found an empty line, remove it
|
|
352
|
+
set results $results[1..-2]
|
|
353
|
+
else
|
|
354
|
+
# Found non-empty line, we have our proper output
|
|
355
|
+
break
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
set -l comps $results[1..-2]
|
|
360
|
+
set -l directiveLine $results[-1]
|
|
361
|
+
|
|
362
|
+
# For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)
|
|
363
|
+
# completions must be prefixed with the flag
|
|
364
|
+
set -l flagPrefix (string match -r -- '-.*=' "$lastArg")
|
|
365
|
+
|
|
366
|
+
__${e}_debug "Comps: $comps"
|
|
367
|
+
__${e}_debug "DirectiveLine: $directiveLine"
|
|
368
|
+
__${e}_debug "flagPrefix: $flagPrefix"
|
|
369
|
+
|
|
370
|
+
for comp in $comps
|
|
371
|
+
printf "%s%s\\n" "$flagPrefix" "$comp"
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
printf "%s\\n" "$directiveLine"
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
# This function limits calls to __${e}_perform_completion, by caching the result
|
|
378
|
+
function __${e}_perform_completion_once
|
|
379
|
+
__${e}_debug "Starting __${e}_perform_completion_once"
|
|
380
|
+
|
|
381
|
+
if test -n "$__${e}_perform_completion_once_result"
|
|
382
|
+
__${e}_debug "Seems like a valid result already exists, skipping __${e}_perform_completion"
|
|
383
|
+
return 0
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
set --global __${e}_perform_completion_once_result (__${e}_perform_completion)
|
|
387
|
+
if test -z "$__${e}_perform_completion_once_result"
|
|
388
|
+
__${e}_debug "No completions, probably due to a failure"
|
|
389
|
+
return 1
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
__${e}_debug "Performed completions and set __${e}_perform_completion_once_result"
|
|
393
|
+
return 0
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
# This function is used to clear the cached result after completions are run
|
|
397
|
+
function __${e}_clear_perform_completion_once_result
|
|
398
|
+
__${e}_debug ""
|
|
399
|
+
__${e}_debug "========= clearing previously set __${e}_perform_completion_once_result variable =========="
|
|
400
|
+
set --erase __${e}_perform_completion_once_result
|
|
401
|
+
__${e}_debug "Successfully erased the variable __${e}_perform_completion_once_result"
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
function __${e}_requires_order_preservation
|
|
405
|
+
__${e}_debug ""
|
|
406
|
+
__${e}_debug "========= checking if order preservation is required =========="
|
|
407
|
+
|
|
408
|
+
__${e}_perform_completion_once
|
|
409
|
+
if test -z "$__${e}_perform_completion_once_result"
|
|
410
|
+
__${e}_debug "Error determining if order preservation is required"
|
|
411
|
+
return 1
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
set -l directive (string sub --start 2 $__${e}_perform_completion_once_result[-1])
|
|
415
|
+
__${e}_debug "Directive is: $directive"
|
|
416
|
+
|
|
417
|
+
set -l shellCompDirectiveKeepOrder ${n.ShellCompDirectiveKeepOrder}
|
|
418
|
+
set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)
|
|
419
|
+
__${e}_debug "Keeporder is: $keeporder"
|
|
420
|
+
|
|
421
|
+
if test $keeporder -ne 0
|
|
422
|
+
__${e}_debug "This does require order preservation"
|
|
423
|
+
return 0
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
__${e}_debug "This doesn't require order preservation"
|
|
427
|
+
return 1
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
# This function does two things:
|
|
431
|
+
# - Obtain the completions and store them in the global __${e}_comp_results
|
|
432
|
+
# - Return false if file completion should be performed
|
|
433
|
+
function __${e}_prepare_completions
|
|
434
|
+
__${e}_debug ""
|
|
435
|
+
__${e}_debug "========= starting completion logic =========="
|
|
436
|
+
|
|
437
|
+
# Start fresh
|
|
438
|
+
set --erase __${e}_comp_results
|
|
439
|
+
|
|
440
|
+
__${e}_perform_completion_once
|
|
441
|
+
__${e}_debug "Completion results: $__${e}_perform_completion_once_result"
|
|
442
|
+
|
|
443
|
+
if test -z "$__${e}_perform_completion_once_result"
|
|
444
|
+
__${e}_debug "No completion, probably due to a failure"
|
|
445
|
+
# Might as well do file completion, in case it helps
|
|
446
|
+
return 1
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
set -l directive (string sub --start 2 $__${e}_perform_completion_once_result[-1])
|
|
450
|
+
set --global __${e}_comp_results $__${e}_perform_completion_once_result[1..-2]
|
|
451
|
+
|
|
452
|
+
__${e}_debug "Completions are: $__${e}_comp_results"
|
|
453
|
+
__${e}_debug "Directive is: $directive"
|
|
454
|
+
|
|
455
|
+
set -l shellCompDirectiveError ${o}
|
|
456
|
+
set -l shellCompDirectiveNoSpace ${l}
|
|
457
|
+
set -l shellCompDirectiveNoFileComp ${r}
|
|
458
|
+
set -l shellCompDirectiveFilterFileExt ${s}
|
|
459
|
+
set -l shellCompDirectiveFilterDirs ${a}
|
|
460
|
+
|
|
461
|
+
if test -z "$directive"
|
|
462
|
+
set directive 0
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
|
|
466
|
+
if test $compErr -eq 1
|
|
467
|
+
__${e}_debug "Received error directive: aborting."
|
|
468
|
+
# Might as well do file completion, in case it helps
|
|
469
|
+
return 1
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
|
|
473
|
+
set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
|
|
474
|
+
if test $filefilter -eq 1; or test $dirfilter -eq 1
|
|
475
|
+
__${e}_debug "File extension filtering or directory filtering not supported"
|
|
476
|
+
# Do full file completion instead
|
|
477
|
+
return 1
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
|
|
481
|
+
set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
|
|
482
|
+
|
|
483
|
+
__${e}_debug "nospace: $nospace, nofiles: $nofiles"
|
|
484
|
+
|
|
485
|
+
# If we want to prevent a space, or if file completion is NOT disabled,
|
|
486
|
+
# we need to count the number of valid completions.
|
|
487
|
+
# To do so, we will filter on prefix as the completions we have received
|
|
488
|
+
# may not already be filtered so as to allow fish to match on different
|
|
489
|
+
# criteria than the prefix.
|
|
490
|
+
if test $nospace -ne 0; or test $nofiles -eq 0
|
|
491
|
+
set -l prefix (commandline -t | string escape --style=regex)
|
|
492
|
+
__${e}_debug "prefix: $prefix"
|
|
493
|
+
|
|
494
|
+
set -l completions (string match -r -- "^$prefix.*" $__${e}_comp_results)
|
|
495
|
+
set --global __${e}_comp_results $completions
|
|
496
|
+
__${e}_debug "Filtered completions are: $__${e}_comp_results"
|
|
497
|
+
|
|
498
|
+
# Important not to quote the variable for count to work
|
|
499
|
+
set -l numComps (count $__${e}_comp_results)
|
|
500
|
+
__${e}_debug "numComps: $numComps"
|
|
501
|
+
|
|
502
|
+
if test $numComps -eq 1; and test $nospace -ne 0
|
|
503
|
+
# We must first split on \\t to get rid of the descriptions to be
|
|
504
|
+
# able to check what the actual completion will be.
|
|
505
|
+
# We don't need descriptions anyway since there is only a single
|
|
506
|
+
# real completion which the shell will expand immediately.
|
|
507
|
+
set -l split (string split --max 1 "\\t" $__${e}_comp_results[1])
|
|
508
|
+
|
|
509
|
+
# Fish won't add a space if the completion ends with any
|
|
510
|
+
# of the following characters: @=/:.,
|
|
511
|
+
set -l lastChar (string sub -s -1 -- $split)
|
|
512
|
+
if not string match -r -q "[@=/:.,]" -- "$lastChar"
|
|
513
|
+
# In other cases, to support the "nospace" directive we trick the shell
|
|
514
|
+
# by outputting an extra, longer completion.
|
|
515
|
+
__${e}_debug "Adding second completion to perform nospace directive"
|
|
516
|
+
set --global __${e}_comp_results $split[1] $split[1].
|
|
517
|
+
__${e}_debug "Completions are now: $__${e}_comp_results"
|
|
518
|
+
end
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
if test $numComps -eq 0; and test $nofiles -eq 0
|
|
522
|
+
# To be consistent with bash and zsh, we only trigger file
|
|
523
|
+
# completion when there are no other completions
|
|
524
|
+
__${e}_debug "Requesting file completion"
|
|
525
|
+
return 1
|
|
526
|
+
end
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
return 0
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
|
|
533
|
+
# so we can properly delete any completions provided by another script.
|
|
534
|
+
# Only do this if the program can be found, or else fish may print some errors; besides,
|
|
535
|
+
# the existing completions will only be loaded if the program can be found.
|
|
536
|
+
if type -q "${t}"
|
|
537
|
+
# The space after the program name is essential to trigger completion for the program
|
|
538
|
+
# and not completion of the program name itself.
|
|
539
|
+
# Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
|
|
540
|
+
complete --do-complete "${t} " > /dev/null 2>&1
|
|
541
|
+
end
|
|
542
|
+
|
|
543
|
+
# Remove any pre-existing completions for the program since we will be handling all of them.
|
|
544
|
+
complete -c ${t} -e
|
|
545
|
+
|
|
546
|
+
# This will get called after the two calls below and clear the cached result
|
|
547
|
+
complete -c ${t} -n '__${e}_clear_perform_completion_once_result'
|
|
548
|
+
# The call to __${e}_prepare_completions will setup __${e}_comp_results
|
|
549
|
+
# which provides the program's completion choices.
|
|
550
|
+
# If this doesn't require order preservation, we don't use the -k flag
|
|
551
|
+
complete -c ${t} -n 'not __${e}_requires_order_preservation && __${e}_prepare_completions' -f -a '$__${e}_comp_results'
|
|
552
|
+
# Otherwise we use the -k flag
|
|
553
|
+
complete -k -c ${t} -n '__${e}_requires_order_preservation && __${e}_prepare_completions' -f -a '$__${e}_comp_results'
|
|
554
|
+
`}function C(t,i){let e=t.replace(/[-:]/g,"_");return`# powershell completion for ${t} -*- shell-script -*-
|
|
555
|
+
|
|
556
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
557
|
+
function __${t}_debug {
|
|
558
|
+
if ($env:BASH_COMP_DEBUG_FILE) {
|
|
559
|
+
"$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
filter __${t}_escapeStringWithSpecialChars {
|
|
564
|
+
$_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\`$&'
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
[scriptblock]$__${e}CompleterBlock = {
|
|
568
|
+
param(
|
|
569
|
+
$WordToComplete,
|
|
570
|
+
$CommandAst,
|
|
571
|
+
$CursorPosition
|
|
572
|
+
)
|
|
573
|
+
|
|
574
|
+
# Get the current command line and convert into a string
|
|
575
|
+
$Command = $CommandAst.CommandElements
|
|
576
|
+
$Command = "$Command"
|
|
577
|
+
|
|
578
|
+
__${t}_debug ""
|
|
579
|
+
__${t}_debug "========= starting completion logic =========="
|
|
580
|
+
__${t}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
|
|
581
|
+
|
|
582
|
+
# The user could have moved the cursor backwards on the command-line.
|
|
583
|
+
# We need to trigger completion from the $CursorPosition location, so we need
|
|
584
|
+
# to truncate the command-line ($Command) up to the $CursorPosition location.
|
|
585
|
+
# Make sure the $Command is longer then the $CursorPosition before we truncate.
|
|
586
|
+
# This happens because the $Command does not include the last space.
|
|
587
|
+
if ($Command.Length -gt $CursorPosition) {
|
|
588
|
+
$Command = $Command.Substring(0, $CursorPosition)
|
|
589
|
+
}
|
|
590
|
+
__${t}_debug "Truncated command: $Command"
|
|
591
|
+
|
|
592
|
+
$ShellCompDirectiveError=${n.ShellCompDirectiveError}
|
|
593
|
+
$ShellCompDirectiveNoSpace=${n.ShellCompDirectiveNoSpace}
|
|
594
|
+
$ShellCompDirectiveNoFileComp=${n.ShellCompDirectiveNoFileComp}
|
|
595
|
+
$ShellCompDirectiveFilterFileExt=${n.ShellCompDirectiveFilterFileExt}
|
|
596
|
+
$ShellCompDirectiveFilterDirs=${n.ShellCompDirectiveFilterDirs}
|
|
597
|
+
$ShellCompDirectiveKeepOrder=${n.ShellCompDirectiveKeepOrder}
|
|
598
|
+
|
|
599
|
+
# Prepare the command to request completions for the program.
|
|
600
|
+
# Split the command at the first space to separate the program and arguments.
|
|
601
|
+
$Program, $Arguments = $Command.Split(" ", 2)
|
|
602
|
+
|
|
603
|
+
$QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
|
|
604
|
+
__${t}_debug "QuotedArgs: $QuotedArgs"
|
|
605
|
+
|
|
606
|
+
$RequestComp = "& ${i} complete '--' $QuotedArgs"
|
|
607
|
+
__${t}_debug "RequestComp: $RequestComp"
|
|
608
|
+
|
|
609
|
+
# we cannot use $WordToComplete because it
|
|
610
|
+
# has the wrong values if the cursor was moved
|
|
611
|
+
# so use the last argument
|
|
612
|
+
if ($WordToComplete -ne "" ) {
|
|
613
|
+
$WordToComplete = $Arguments.Split(" ")[-1]
|
|
614
|
+
}
|
|
615
|
+
__${t}_debug "New WordToComplete: $WordToComplete"
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
# Check for flag with equal sign
|
|
619
|
+
$IsEqualFlag = ($WordToComplete -Like "--*=*" )
|
|
620
|
+
if ( $IsEqualFlag ) {
|
|
621
|
+
__${t}_debug "Completing equal sign flag"
|
|
622
|
+
# Remove the flag part
|
|
623
|
+
$Flag, $WordToComplete = $WordToComplete.Split("=", 2)
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
|
|
627
|
+
# If the last parameter is complete (there is a space following it)
|
|
628
|
+
# We add an extra empty parameter so we can indicate this to the go method.
|
|
629
|
+
__${t}_debug "Adding extra empty parameter"
|
|
630
|
+
# PowerShell 7.2+ changed the way how the arguments are passed to executables,
|
|
631
|
+
# so for pre-7.2 or when Legacy argument passing is enabled we need to use
|
|
632
|
+
if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
|
|
633
|
+
($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or
|
|
634
|
+
(($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and
|
|
635
|
+
$PSNativeCommandArgumentPassing -eq 'Legacy')) {
|
|
636
|
+
$RequestComp="$RequestComp" + ' \`"\`"'
|
|
637
|
+
} else {
|
|
638
|
+
$RequestComp = "$RequestComp" + ' ""'
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
__${t}_debug "Calling $RequestComp"
|
|
643
|
+
# First disable ActiveHelp which is not supported for Powershell
|
|
644
|
+
$env:ActiveHelp = 0
|
|
645
|
+
|
|
646
|
+
# call the command store the output in $out and redirect stderr and stdout to null
|
|
647
|
+
# $Out is an array contains each line per element
|
|
648
|
+
Invoke-Expression -OutVariable out "$RequestComp" 2>&1 | Out-Null
|
|
649
|
+
|
|
650
|
+
# get directive from last line
|
|
651
|
+
[int]$Directive = $Out[-1].TrimStart(':')
|
|
652
|
+
if ($Directive -eq "") {
|
|
653
|
+
# There is no directive specified
|
|
654
|
+
$Directive = 0
|
|
655
|
+
}
|
|
656
|
+
__${t}_debug "The completion directive is: $Directive"
|
|
657
|
+
|
|
658
|
+
# remove directive (last element) from out
|
|
659
|
+
$Out = $Out | Where-Object { $_ -ne $Out[-1] }
|
|
660
|
+
__${t}_debug "The completions are: $Out"
|
|
661
|
+
|
|
662
|
+
if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
|
|
663
|
+
# Error code. No completion.
|
|
664
|
+
__${t}_debug "Received error from custom completion go code"
|
|
665
|
+
return
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
$Longest = 0
|
|
669
|
+
[Array]$Values = $Out | ForEach-Object {
|
|
670
|
+
# Split the output in name and description
|
|
671
|
+
$Name, $Description = $_.Split("\`t", 2)
|
|
672
|
+
__${t}_debug "Name: $Name Description: $Description"
|
|
673
|
+
|
|
674
|
+
# Look for the longest completion so that we can format things nicely
|
|
675
|
+
if ($Longest -lt $Name.Length) {
|
|
676
|
+
$Longest = $Name.Length
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
# Set the description to a one space string if there is none set.
|
|
680
|
+
# This is needed because the CompletionResult does not accept an empty string as argument
|
|
681
|
+
if (-Not $Description) {
|
|
682
|
+
$Description = " "
|
|
683
|
+
}
|
|
684
|
+
@{ Name = "$Name"; Description = "$Description" }
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
$Space = " "
|
|
689
|
+
if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
|
|
690
|
+
# remove the space here
|
|
691
|
+
__${t}_debug "ShellCompDirectiveNoSpace is called"
|
|
692
|
+
$Space = ""
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
|
|
696
|
+
(($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
|
|
697
|
+
__${t}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
|
|
698
|
+
|
|
699
|
+
# return here to prevent the completion of the extensions
|
|
700
|
+
return
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
$Values = $Values | Where-Object {
|
|
704
|
+
# filter the result
|
|
705
|
+
$_.Name -like "$WordToComplete*"
|
|
706
|
+
|
|
707
|
+
# Join the flag back if we have an equal sign flag
|
|
708
|
+
if ( $IsEqualFlag ) {
|
|
709
|
+
__${t}_debug "Join the equal sign flag back to the completion value"
|
|
710
|
+
$_.Name = $Flag + "=" + $_.Name
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
# we sort the values in ascending order by name if keep order isn't passed
|
|
715
|
+
if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) {
|
|
716
|
+
$Values = $Values | Sort-Object -Property Name
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
|
|
720
|
+
__${t}_debug "ShellCompDirectiveNoFileComp is called"
|
|
721
|
+
|
|
722
|
+
if ($Values.Length -eq 0) {
|
|
723
|
+
# Just print an empty string here so the
|
|
724
|
+
# shell does not start to complete paths.
|
|
725
|
+
# We cannot use CompletionResult here because
|
|
726
|
+
# it does not accept an empty string as argument.
|
|
727
|
+
""
|
|
728
|
+
return
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
# Get the current mode
|
|
733
|
+
$Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
|
|
734
|
+
__${t}_debug "Mode: $Mode"
|
|
735
|
+
|
|
736
|
+
$Values | ForEach-Object {
|
|
737
|
+
|
|
738
|
+
# store temporary because switch will overwrite $_
|
|
739
|
+
$comp = $_
|
|
740
|
+
|
|
741
|
+
# PowerShell supports three different completion modes
|
|
742
|
+
# - TabCompleteNext (default windows style - on each key press the next option is displayed)
|
|
743
|
+
# - Complete (works like bash)
|
|
744
|
+
# - MenuComplete (works like zsh)
|
|
745
|
+
# You set the mode with Set-PSReadLineKeyHandler -Key Tab -Function <mode>
|
|
746
|
+
|
|
747
|
+
# CompletionResult Arguments:
|
|
748
|
+
# 1) CompletionText text to be used as the auto completion result
|
|
749
|
+
# 2) ListItemText text to be displayed in the suggestion list
|
|
750
|
+
# 3) ResultType type of completion result
|
|
751
|
+
# 4) ToolTip text for the tooltip with details about the object
|
|
752
|
+
|
|
753
|
+
switch ($Mode) {
|
|
754
|
+
|
|
755
|
+
# bash like
|
|
756
|
+
"Complete" {
|
|
757
|
+
|
|
758
|
+
if ($Values.Length -eq 1) {
|
|
759
|
+
__${t}_debug "Only one completion left"
|
|
760
|
+
|
|
761
|
+
# insert space after value
|
|
762
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
763
|
+
|
|
764
|
+
} else {
|
|
765
|
+
# Add the proper number of spaces to align the descriptions
|
|
766
|
+
while($comp.Name.Length -lt $Longest) {
|
|
767
|
+
$comp.Name = $comp.Name + " "
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
# Check for empty description and only add parentheses if needed
|
|
771
|
+
if ($($comp.Description) -eq " " ) {
|
|
772
|
+
$Description = ""
|
|
773
|
+
} else {
|
|
774
|
+
$Description = " ($($comp.Description))"
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
[System.Management.Automation.CompletionResult]::new("$($comp.Name)$Description", "$($comp.Name)$Description", 'ParameterValue', "$($comp.Description)")
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
# zsh like
|
|
782
|
+
"MenuComplete" {
|
|
783
|
+
# insert space after value
|
|
784
|
+
# MenuComplete will automatically show the ToolTip of
|
|
785
|
+
# the highlighted value at the bottom of the suggestions.
|
|
786
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
# TabCompleteNext and in case we get something unknown
|
|
790
|
+
Default {
|
|
791
|
+
# Like MenuComplete but we don't want to add a space here because
|
|
792
|
+
# the user need to press space anyway to get the completion.
|
|
793
|
+
# Description will not be shown because that's not possible with TabCompleteNext
|
|
794
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
Register-ArgumentCompleter -CommandName '${t}' -ScriptBlock $__${e}CompleterBlock
|
|
802
|
+
`}const n={ShellCompDirectiveError:1,ShellCompDirectiveNoSpace:2,ShellCompDirectiveNoFileComp:4,ShellCompDirectiveFilterFileExt:8,ShellCompDirectiveFilterDirs:16,ShellCompDirectiveKeepOrder:32,ShellCompDirectiveDefault:0};var b=class{name;variadic;command;handler;constructor(t,i,e,o=!1){this.command=t,this.name=i,this.handler=e,this.variadic=o}},w=class{value;description;command;handler;alias;isBoolean;constructor(t,i,e,o,l,r){this.command=t,this.value=i,this.description=e,this.handler=o,this.alias=l,this.isBoolean=r}},m=class{value;description;options=new Map;arguments=new Map;parent;constructor(t,i){this.value=t,this.description=i}option(t,i,e,o){let l,r,s;typeof e=="function"?(l=e,r=o,s=!1):typeof e=="string"?(l=void 0,r=e,s=!0):(l=void 0,r=void 0,s=!0);let a=new w(this,t,i,l,r,s);return this.options.set(t,a),this}argument(t,i,e=!1){let o=new b(this,t,i,e);return this.arguments.set(t,o),this}},D=class extends m{commands=new Map;completions=[];directive=n.ShellCompDirectiveDefault;constructor(){super("","")}command(t,i){let e=new m(t,i);return this.commands.set(t,e),e}stripOptions(t){let i=[],e=0;for(;e<t.length;){let o=t[e];if(o.startsWith("-")){e++;let l=!1,r=this.findOption(this,o);if(r)l=r.isBoolean??!1;else for(let[,s]of this.commands){let a=this.findOption(s,o);if(a){l=a.isBoolean??!1;break}}!l&&e<t.length&&!t[e].startsWith("-")&&e++}else i.push(o),e++}return i}matchCommand(t){t=this.stripOptions(t);let i=[],e=[],o=null;for(let l=0;l<t.length;l++){let r=t[l];i.push(r);let s=this.commands.get(i.join(" "));if(s)o=s;else{e=t.slice(l,t.length);break}}return[o||this,e]}shouldCompleteFlags(t,i){if(i.startsWith("-"))return!0;if(t?.startsWith("-")){let e=this.findOption(this,t);if(!e){for(let[,o]of this.commands)if(e=this.findOption(o,t),e)break}return!(e&&e.isBoolean)}return!1}shouldCompleteCommands(t){return!t.startsWith("-")}handleFlagCompletion(t,i,e,o){let l;if(e.includes("=")){let[r]=e.split("=");l=r}else if(o?.startsWith("-")){let r=this.findOption(t,o);r&&!r.isBoolean&&(l=o)}if(l){let r=this.findOption(t,l);if(r?.handler){let s=[];r.handler.call(r,(a,c)=>s.push({value:a,description:c}),t.options),this.completions=s}return}if(e.startsWith("-")){let r=e.startsWith("-")&&!e.startsWith("--"),s=e.replace(/^-+/,"");for(let[a,c]of t.options)r&&c.alias&&`-${c.alias}`.startsWith(e)?this.completions.push({value:`-${c.alias}`,description:c.description}):!r&&a.startsWith(s)&&this.completions.push({value:`--${a}`,description:c.description})}}findOption(t,i){let e=t.options.get(i);if(e||(e=t.options.get(i.replace(/^-+/,"")),e))return e;for(let[o,l]of t.options)if(l.alias&&`-${l.alias}`===i)return l}handleCommandCompletion(t,i){let e=this.stripOptions(t);for(let[o,l]of this.commands){if(o==="")continue;let r=o.split(" ");r.slice(0,e.length).every((s,a)=>s===e[a])&&r[e.length]?.startsWith(i)&&this.completions.push({value:r[e.length],description:l.description})}}handlePositionalCompletion(t,i){let e=this.stripOptions(i),o=t.value.split(" ").length,l=Math.max(0,e.length-o),r=Array.from(t.arguments.entries());if(r.length>0){let s;if(l<r.length){let[a,c]=r[l];s=c}else{let a=r[r.length-1][1];a.variadic&&(s=a)}if(s&&s.handler&&typeof s.handler=="function"){let a=[];s.handler.call(s,(c,d)=>a.push({value:c,description:d}),t.options),this.completions.push(...a)}}}complete(t){this.directive=n.ShellCompDirectiveNoFileComp;let i=new Set;this.completions.filter(e=>i.has(e.value)?!1:(i.add(e.value),!0)).filter(e=>{if(t.includes("=")){let[,o]=t.split("=");return e.value.startsWith(o)}return e.value.startsWith(t)}).forEach(e=>console.log(`${e.value} ${e.description??""}`)),console.log(`:${this.directive}`)}parse(t){this.completions=[];let i=t[t.length-1]==="";i&&t.pop();let e=t[t.length-1]||"",o=t.slice(0,-1);i&&(e!==""&&o.push(e),e="");let[l]=this.matchCommand(o),r=o[o.length-1];this.shouldCompleteFlags(r,e)?this.handleFlagCompletion(l,o,e,r):(this.shouldCompleteCommands(e)&&this.handleCommandCompletion(o,e),l&&l.arguments.size>0&&this.handlePositionalCompletion(l,o)),this.complete(e)}setup(t,i,e){switch($(e==="zsh"||e==="bash"||e==="fish"||e==="powershell","Unsupported shell"),e){case"zsh":{let o=f(t,i);console.log(o);break}case"bash":{let o=g(t,i);console.log(o);break}case"fish":{let o=v(t,i);console.log(o);break}case"powershell":{let o=C(t,i);console.log(o);break}}}};const F=new D;export{b as Argument,m as Command,w as Option,D as RootCommand,n as ShellCompDirective,F as default};
|