aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/tmpls/comps
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-09 02:51:06 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-09 02:51:25 +0800
commitba02e78e26991a99744f9b546626c314f6bd7982 (patch)
tree70cb396b60023d427bdbfc58c7e84f23be10ee4e /mingling_core/tmpls/comps
parentc55d5f8142e48ae9f9a21cda3c82e4c4c9198fb9 (diff)
fix(comps): fix PowerShell completion word index and arg passing
Correct off-by-one word index computation and conditionally pass option values only when non-empty to avoid spurious parsing.
Diffstat (limited to 'mingling_core/tmpls/comps')
-rw-r--r--mingling_core/tmpls/comps/pwsh.ps131
1 files changed, 23 insertions, 8 deletions
diff --git a/mingling_core/tmpls/comps/pwsh.ps1 b/mingling_core/tmpls/comps/pwsh.ps1
index eccb776..d72a027 100644
--- a/mingling_core/tmpls/comps/pwsh.ps1
+++ b/mingling_core/tmpls/comps/pwsh.ps1
@@ -18,7 +18,7 @@ Register-ArgumentCompleter -Native -CommandName '<<<bin_name>>>' -ScriptBlock {
$found = $false
for ($i = 0; $i -lt $elements.Count; $i++) {
if ($elements[$i] -eq $currentWord) {
- $wordIndex = $i
+ $wordIndex = $i + 1
if ($i -gt 0) {
$previousWord = $elements[$i - 1]
}
@@ -28,25 +28,40 @@ Register-ArgumentCompleter -Native -CommandName '<<<bin_name>>>' -ScriptBlock {
}
if (-not $found) {
- $wordIndex = $elements.Count
+ $wordIndex = $elements.Count + 1
if ($elements.Count -gt 0) {
$previousWord = $elements[-1]
}
}
$args = @(
- "-f", ($line -replace '-', '^')
"-C", $cursorPosition.ToString()
- "-w", ($currentWord -replace '-', '^')
- "-p", ($previousWord -replace '-', '^')
- "-c", ($commandName -replace '-', '^')
"-i", $wordIndex.ToString()
"-F", "Powershell"
)
+ if ($line) {
+ $args += "-f"
+ $args += ($line -replace '-', '^')
+ }
+ if ($currentWord) {
+ $args += "-w"
+ $args += ($currentWord -replace '-', '^')
+ }
+ if ($previousWord) {
+ $args += "-p"
+ $args += ($previousWord -replace '-', '^')
+ }
+ if ($commandName) {
+ $args += "-c"
+ $args += ($commandName -replace '-', '^')
+ }
+
foreach ($element in $elements) {
- $args += "-a"
- $args += ($element -replace '-', '^')
+ if ($element) {
+ $args += "-a"
+ $args += ($element -replace '-', '^')
+ }
}
$originalEncoding = [Console]::OutputEncoding