From 643b5ccb1c27e76a03e85dc6fb9137c020dcae01 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 12 Apr 2026 03:55:38 +0800 Subject: Fix typo in PowerShell shell flag from "pwsl" to "pwsh" --- README.md | 2 +- mingling_core/src/asset/comp/flags.rs | 2 +- mingling_core/src/builds/comp.rs | 4 ++-- mingling_core/tmpls/comps/pwsh.ps1 | 43 +++++++++++++++++++++++++++++++++++ mingling_core/tmpls/comps/pwsl.ps1 | 43 ----------------------------------- 5 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 mingling_core/tmpls/comps/pwsh.ps1 delete mode 100644 mingling_core/tmpls/comps/pwsl.ps1 diff --git a/README.md b/README.md index ddbbe87..27e49f8 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ You can read the following docs to learn more about the `Mingling` framework: ## Roadmap - [x] core: \[[0.1.4](https://docs.rs/mingling/0.1.4/mingling/)\] General Renderers *( Json, Yaml, Toml, Ron )* -- [x] core: \[[0.1.5](https://docs.rs/mingling/0.1.5/mingling/)\] Completion *( Bash Zsh Fish Pwsl )* +- [x] core: \[[0.1.5](https://docs.rs/mingling/0.1.5/mingling/)\] Completion *( Bash Zsh Fish Pwsh )* - [ ] core: \[**0.2.0**\] Parallel Chains - [ ] \[**0.2.1**\] Helpdoc - [ ] \[**unplanned**\] Parser Theme diff --git a/mingling_core/src/asset/comp/flags.rs b/mingling_core/src/asset/comp/flags.rs index 0762d0d..f61e9ac 100644 --- a/mingling_core/src/asset/comp/flags.rs +++ b/mingling_core/src/asset/comp/flags.rs @@ -17,7 +17,7 @@ impl From for ShellFlag { "zsh" => ShellFlag::Zsh, "bash" => ShellFlag::Bash, "fish" => ShellFlag::Fish, - "pwsl" | "ps1" | "powershell" => ShellFlag::Powershell, + "pwsh" | "ps1" | "powershell" => ShellFlag::Powershell, other => ShellFlag::Other(snake_case!(other)), } } diff --git a/mingling_core/src/builds/comp.rs b/mingling_core/src/builds/comp.rs index 694af0c..57faa2e 100644 --- a/mingling_core/src/builds/comp.rs +++ b/mingling_core/src/builds/comp.rs @@ -5,7 +5,7 @@ use crate::ShellFlag; const TMPL_COMP_BASH: &str = include_str!("../../tmpls/comps/bash.sh"); const TMPL_COMP_ZSH: &str = include_str!("../../tmpls/comps/zsh.zsh"); const TMPL_COMP_FISH: &str = include_str!("../../tmpls/comps/fish.fish"); -const TMPL_COMP_PWSL: &str = include_str!("../../tmpls/comps/pwsl.ps1"); +const TMPL_COMP_PWSH: &str = include_str!("../../tmpls/comps/pwsh.ps1"); /// Generate shell completion scripts for the current binary. /// On Windows, generates PowerShell completion. @@ -74,7 +74,7 @@ fn get_tmpl(shell_flag: &ShellFlag) -> (&'static str, &'static str) { ShellFlag::Bash => (TMPL_COMP_BASH, ".sh"), ShellFlag::Zsh => (TMPL_COMP_ZSH, ".zsh"), ShellFlag::Fish => (TMPL_COMP_FISH, ".fish"), - ShellFlag::Powershell => (TMPL_COMP_PWSL, ".ps1"), + ShellFlag::Powershell => (TMPL_COMP_PWSH, ".ps1"), ShellFlag::Other(_) => (TMPL_COMP_BASH, ".sh"), } } diff --git a/mingling_core/tmpls/comps/pwsh.ps1 b/mingling_core/tmpls/comps/pwsh.ps1 new file mode 100644 index 0000000..6d7d91d --- /dev/null +++ b/mingling_core/tmpls/comps/pwsh.ps1 @@ -0,0 +1,43 @@ +Register-ArgumentCompleter -CommandName <<>> -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + + $line = $commandAst.ToString() + $commandName = if ($commandAst.CommandElements.Count -gt 0) { + $commandAst.CommandElements[0].Value + } else { "" } + + $words = @() + $currentIndex = 0 + $parser = [System.Management.Automation.PSParser] + $tokens = $parser::Tokenize($line, [ref]$null) + + foreach ($token in $tokens) { + if ($token.Type -in 'CommandArgument', 'CommandParameter') { + $words += $token.Content + } + } + + $args = @( + "-f", ($line -replace '-', '^') + "-C", $cursorPosition.ToString() + "-w", ($wordToComplete -replace '-', '^') + "-p", (if ($words.Count -gt 1) { $words[-2] } else { "" }) -replace '-', '^' + "-c", $commandName + "-i", ($words.Count - 1).ToString() + "-a", ($words | ForEach-Object { $_ -replace '-', '^' }) + "-F", "powershell" + ) + + $suggestions = <<>> __comp $args 2>$null + + if ($suggestions) { + $suggestions | ForEach-Object { + if ($_ -eq "_file_") { + $completionType = 'ProviderItem' + } else { + $completionType = 'ParameterValue' + } + [System.Management.Automation.CompletionResult]::new($_, $_, $completionType, $_) + } + } +} diff --git a/mingling_core/tmpls/comps/pwsl.ps1 b/mingling_core/tmpls/comps/pwsl.ps1 deleted file mode 100644 index 6d7d91d..0000000 --- a/mingling_core/tmpls/comps/pwsl.ps1 +++ /dev/null @@ -1,43 +0,0 @@ -Register-ArgumentCompleter -CommandName <<>> -ScriptBlock { - param($wordToComplete, $commandAst, $cursorPosition) - - $line = $commandAst.ToString() - $commandName = if ($commandAst.CommandElements.Count -gt 0) { - $commandAst.CommandElements[0].Value - } else { "" } - - $words = @() - $currentIndex = 0 - $parser = [System.Management.Automation.PSParser] - $tokens = $parser::Tokenize($line, [ref]$null) - - foreach ($token in $tokens) { - if ($token.Type -in 'CommandArgument', 'CommandParameter') { - $words += $token.Content - } - } - - $args = @( - "-f", ($line -replace '-', '^') - "-C", $cursorPosition.ToString() - "-w", ($wordToComplete -replace '-', '^') - "-p", (if ($words.Count -gt 1) { $words[-2] } else { "" }) -replace '-', '^' - "-c", $commandName - "-i", ($words.Count - 1).ToString() - "-a", ($words | ForEach-Object { $_ -replace '-', '^' }) - "-F", "powershell" - ) - - $suggestions = <<>> __comp $args 2>$null - - if ($suggestions) { - $suggestions | ForEach-Object { - if ($_ -eq "_file_") { - $completionType = 'ProviderItem' - } else { - $completionType = 'ParameterValue' - } - [System.Management.Automation.CompletionResult]::new($_, $_, $completionType, $_) - } - } -} -- cgit