diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-11-23 14:22:21 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-11-23 14:22:21 +0800 |
| commit | 3f5b8bda0af9e89bc3d454038f8957f217b9ec24 (patch) | |
| tree | 6439d2142bd7a363d15f7f1471bfce78c9b38ce7 | |
| parent | 272d67c53bb7b16e421f55f8c9c3e068b3f7e2d9 (diff) | |
Reorganize PowerShell completion scripts
- Move completion_jv.ps1 to completions/powershell directory - Add new
completion_jvv.ps1 for jvv command - Update header comment format for
consistency
| -rw-r--r-- | scripts/completions/powershell/completion_jv.ps1 (renamed from scripts/completion_jv.ps1) | 3 | ||||
| -rwxr-xr-x | scripts/completions/powershell/completion_jvv.ps1 | 67 |
2 files changed, 69 insertions, 1 deletions
diff --git a/scripts/completion_jv.ps1 b/scripts/completions/powershell/completion_jv.ps1 index 0b22133..48ab3ec 100644 --- a/scripts/completion_jv.ps1 +++ b/scripts/completions/powershell/completion_jv.ps1 @@ -1,4 +1,5 @@ -# JustEnoughVCS PowerShell Completion +# The JustEnoughVCS CommandLine Completion + Register-ArgumentCompleter -Native -CommandName jv -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) diff --git a/scripts/completions/powershell/completion_jvv.ps1 b/scripts/completions/powershell/completion_jvv.ps1 new file mode 100755 index 0000000..fa773c0 --- /dev/null +++ b/scripts/completions/powershell/completion_jvv.ps1 @@ -0,0 +1,67 @@ +# The JustEnoughVCS CommandLine Completion + +Register-ArgumentCompleter -Native -CommandName jvv -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + + $words = $commandAst.CommandElements | ForEach-Object { $_.ToString() } + $currentIndex = $words.IndexOf($wordToComplete) + if ($currentIndex -lt 0) { $currentIndex = $words.Count } + + $cmd = "jvv" + $subcmd = if ($words.Count -gt 1) { $words[1] } else { $null } + $subsubcmd = if ($words.Count -gt 2) { $words[2] } else { $null } + + # Base commands + $baseCommands = @("create", "init", "here", "member", "service", "listen", "members", "-c", "-i", "-H", "-m", "-l", "-M") + + # Member subcommands + $memberCommands = @("register", "remove", "list", "help", "+", "-", "ls") + + # Service subcommands + $serviceCommands = @("listen", "help") + + # Completion for main command + if ($currentIndex -eq 1) { + return $baseCommands | Where-Object { $_ -like "$wordToComplete*" } + } + + # Completion for member command + if ($subcmd -eq "member" -or $subcmd -eq "-m") { + if ($currentIndex -eq 2) { + return $memberCommands | Where-Object { $_ -like "$wordToComplete*" } + } + + switch ($subsubcmd) { + { @("remove", "-") -contains $_ } { + if ($currentIndex -eq 3) { + $members = & $cmd member list --raw 2>$null + return $members | Where-Object { $_ -like "$wordToComplete*" } + } + } + } + return @() + } + + # Completion for service command + if ($subcmd -eq "service") { + if ($currentIndex -eq 2) { + return $serviceCommands | Where-Object { $_ -like "$wordToComplete*" } + } + return @() + } + + # Aliases completion + switch ($subcmd) { + "-m" { + if ($currentIndex -eq 2) { + return $memberCommands | Where-Object { $_ -like "$wordToComplete*" } + } + } + { @("listen", "-l", "members", "-M") -contains $_ } { + # These commands have no arguments to complete + return @() + } + } + + return @() +} |
