diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-04-12 20:50:44 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-04-12 20:50:51 +0800 |
| commit | c7817348618fbc7eedadb3ba56e4784ec12dd4af (patch) | |
| tree | a85e361b0651dde05d334a8526bec0beaf82089c /mingling_core/tmpls/comps | |
| parent | 40578ba8e008e69d8fa0615a822b286617f37adb (diff) | |
Use same suggestion format for PowerShell as Zsh
Diffstat (limited to 'mingling_core/tmpls/comps')
| -rw-r--r-- | mingling_core/tmpls/comps/pwsh.ps1 | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/mingling_core/tmpls/comps/pwsh.ps1 b/mingling_core/tmpls/comps/pwsh.ps1 index 8a52a4f..610522b 100644 --- a/mingling_core/tmpls/comps/pwsh.ps1 +++ b/mingling_core/tmpls/comps/pwsh.ps1 @@ -36,35 +36,41 @@ Register-ArgumentCompleter -Native -CommandName '<<<bin_name>>>' -ScriptBlock { } $completions | ForEach-Object { - $path = $_.Replace('^', '-') + $path = $_ $isDirectory = $path.EndsWith([System.IO.Path]::DirectorySeparatorChar) -or $path.EndsWith('/') $completionType = if ($isDirectory) { 'ProviderContainer' } else { 'ProviderItem' } [System.Management.Automation.CompletionResult]::new($path, $path, $completionType, $path) } } else { - $parsedCompletions = @() + $completionItems = @() + foreach ($item in $completions) { if ($item -match '^([^$]+)\$\((.+)\)$') { - $parsedCompletions += "$($matches[1]):$($matches[2])" - } - else { - $parsedCompletions += $item - } - } - - $simpleCompletions = @() - foreach ($item in $parsedCompletions) { - if ($item -match '^([^:]+):(.+)$') { - $simpleCompletions += $matches[1] + $text = $matches[1] + $description = $matches[2] + $completionItems += @{ + Text = $text + Description = $description + } } else { - $simpleCompletions += $item + $text = $item + $completionItems += @{ + Text = $text + Description = $text + } } } - return $simpleCompletions | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + return $completionItems | ForEach-Object { + $resultType = if ($_.Text.StartsWith('-')) { 'ParameterName' } else { 'ParameterValue' } + [System.Management.Automation.CompletionResult]::new( + $_.Text, + $_.Text, + $resultType, + $_.Description + ) } } } |
