From c7817348618fbc7eedadb3ba56e4784ec12dd4af Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Sun, 12 Apr 2026 20:50:44 +0800 Subject: Use same suggestion format for PowerShell as Zsh --- mingling_core/src/asset/comp.rs | 4 ++-- mingling_core/tmpls/comps/pwsh.ps1 | 38 ++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'mingling_core') diff --git a/mingling_core/src/asset/comp.rs b/mingling_core/src/asset/comp.rs index c2e6970..c1c7ab5 100644 --- a/mingling_core/src/asset/comp.rs +++ b/mingling_core/src/asset/comp.rs @@ -93,8 +93,8 @@ impl CompletionHelper { Suggest::Suggest(suggestions) => { trace!("rendering {} suggestions", suggestions.len()); match ctx.shell_flag { - ShellFlag::Zsh => { - trace!("using zsh format"); + ShellFlag::Zsh | ShellFlag::Powershell => { + trace!("using zsh/pwsh format"); print_suggest_with_description(suggestions) } ShellFlag::Fish => { 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 '<<>>' -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 + ) } } } -- cgit