diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-14 22:12:30 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-14 22:40:12 +0800 |
| commit | 72f80ea51f25256d0c463c2f3dc3d8670cfc4634 (patch) | |
| tree | b200a3ab1a4c718034458863570a064b52bafdcd /scripts/deploy/completions/powershell.ps1 | |
| parent | 54b5567d6f1b1adaa6ada6a26faba0c5c492b7f3 (diff) | |
Add shell completions for new jvn CLI
Diffstat (limited to 'scripts/deploy/completions/powershell.ps1')
| -rw-r--r-- | scripts/deploy/completions/powershell.ps1 | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/deploy/completions/powershell.ps1 b/scripts/deploy/completions/powershell.ps1 new file mode 100644 index 0000000..0c3cddc --- /dev/null +++ b/scripts/deploy/completions/powershell.ps1 @@ -0,0 +1,42 @@ +Register-ArgumentCompleter -CommandName jvn -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 + "-C", $cursorPosition.ToString() + "-w", $wordToComplete + "-p", if ($words.Count -gt 1) { $words[-2] } else { "" } + "-c", $commandName + "-i", ($words.Count - 1).ToString() + "-a", $words + ) + + $suggestions = jvn_comp $args 2>$null + + if ($suggestions) { + $suggestions | ForEach-Object { + if ($_ -eq "_file_") { + $completionType = 'ProviderItem' + } else { + $completionType = 'ParameterValue' + } + [System.Management.Automation.CompletionResult]::new($_, $_, $completionType, $_) + } + } +} |
