aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-04-12 20:50:44 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-04-12 20:50:51 +0800
commitc7817348618fbc7eedadb3ba56e4784ec12dd4af (patch)
treea85e361b0651dde05d334a8526bec0beaf82089c
parent40578ba8e008e69d8fa0615a822b286617f37adb (diff)
Use same suggestion format for PowerShell as Zsh
-rw-r--r--mingling_core/src/asset/comp.rs4
-rw-r--r--mingling_core/tmpls/comps/pwsh.ps138
2 files changed, 24 insertions, 18 deletions
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 '<<<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
+ )
}
}
}