summaryrefslogtreecommitdiff
path: root/scripts/deploy/completions
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-14 22:12:30 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-14 22:40:12 +0800
commit72f80ea51f25256d0c463c2f3dc3d8670cfc4634 (patch)
treeb200a3ab1a4c718034458863570a064b52bafdcd /scripts/deploy/completions
parent54b5567d6f1b1adaa6ada6a26faba0c5c492b7f3 (diff)
Add shell completions for new jvn CLI
Diffstat (limited to 'scripts/deploy/completions')
-rw-r--r--scripts/deploy/completions/bash.sh65
-rwxr-xr-xscripts/deploy/completions/bash/completion_jv.sh272
-rwxr-xr-xscripts/deploy/completions/bash/completion_jvv.sh78
-rw-r--r--scripts/deploy/completions/fish.fish43
-rw-r--r--scripts/deploy/completions/powershell.ps142
-rw-r--r--scripts/deploy/completions/powershell/completion_jv.ps1250
-rw-r--r--scripts/deploy/completions/powershell/completion_jvv.ps167
-rw-r--r--scripts/deploy/completions/zsh.sh48
8 files changed, 198 insertions, 667 deletions
diff --git a/scripts/deploy/completions/bash.sh b/scripts/deploy/completions/bash.sh
new file mode 100644
index 0000000..418105d
--- /dev/null
+++ b/scripts/deploy/completions/bash.sh
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+_jvn_bash_completion() {
+ local cur prev words cword
+
+ local line="${COMP_LINE}"
+ local point="${COMP_POINT}"
+
+ if [ "${point}" -gt "${#line}" ]; then
+ point="${#line}"
+ fi
+
+ words=($line)
+ cword=0
+
+ local i=0
+ local pos=0
+ for word in "${words[@]}"; do
+ local word_start=$pos
+ local word_end=$((pos + ${#word}))
+
+ if [ "${point}" -ge "${word_start}" ] && [ "${point}" -le "${word_end}" ]; then
+ cword=$i
+ cur="${word}"
+ break
+ fi
+
+ pos=$((pos + ${#word} + 1))
+ i=$((i + 1))
+ done
+
+ if [ "${point}" -gt "${pos}" ]; then
+ cword=${#words[@]}
+ cur=""
+ fi
+
+ if [ "${cword}" -gt 0 ]; then
+ prev="${words[$((cword-1))]}"
+ else
+ prev=""
+ fi
+
+ local args=(
+ -f "$COMP_LINE"
+ -C "$COMP_POINT"
+ -w "$cur"
+ -p "$prev"
+ -c "${words[0]}"
+ -i "$cword"
+ -a "${words[@]}"
+ )
+
+ local suggestions
+ if suggestions=$(jvn_comp "${args[@]}" 2>/dev/null); then
+ if [ "$suggestions" = "_file_" ]; then
+ compopt -o default
+ COMPREPLY=()
+ else
+ mapfile -t COMPREPLY < <(printf '%s\n' "$suggestions")
+ fi
+ else
+ COMPREPLY=()
+ fi
+}
+
+complete -F _jvn_bash_completion jvn
diff --git a/scripts/deploy/completions/bash/completion_jv.sh b/scripts/deploy/completions/bash/completion_jv.sh
deleted file mode 100755
index 364df9d..0000000
--- a/scripts/deploy/completions/bash/completion_jv.sh
+++ /dev/null
@@ -1,272 +0,0 @@
-#!/bin/bash
-# The JustEnoughVCS CommandLine Completion
-
-_jv_completion() {
- local cur prev words cword
- COMPREPLY=()
- cur="${COMP_WORDS[COMP_CWORD]}"
- prev="${COMP_WORDS[COMP_CWORD-1]}"
- words=("${COMP_WORDS[@]}")
- cword=$COMP_CWORD
-
- # Current
- local cmd="${words[0]}"
- local subcmd="${words[1]}"
- local subsubcmd="${words[2]}"
-
- # Subcommands
- local base_commands="create init direct unstain account update \
- sheet status here move mv docs exit use sheets accounts \
- as make drop track hold throw login \
- jump align info share"
-
- # Subcommands - Account
- local account_commands="list as add remove movekey mvkey mvk genpub help"
-
- # Subcommands - Sheet
- local sheet_commands="list use exit make drop help align"
-
- # Subcommands - Sheet
- local sheet_commands="list use exit make drop help align"
-
- # Completion subcommands
- if [[ $cword -eq 1 ]]; then
- COMPREPLY=($(compgen -W "$base_commands" -- "$cur"))
- return 0
- fi
-
- # Completion account
- if [[ "$subcmd" == "account" || "$subcmd" == "acc" ]]; then
- if [[ $cword -eq 2 ]]; then
- COMPREPLY=($(compgen -W "$account_commands" -- "$cur"))
- return 0
- fi
-
- case "$subsubcmd" in
- "as"|"remove"|"mvkey"|"mvk"|"movekey"|"genpub")
- if [[ $cword -eq 3 ]]; then
- # Use jv account list --raw
- local accounts
- accounts=$($cmd account list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$accounts" -- "$cur"))
- elif [[ $cword -eq 4 && ("$subsubcmd" == "mvkey" || "$subsubcmd" == "mvk" || "$subsubcmd" == "movekey" || "$subsubcmd" == "genpub") ]]; then
- COMPREPLY=($(compgen -f -- "$cur"))
- fi
- ;;
- "add")
- if [[ $cword -eq 3 ]]; then
- # No completion for account name, let user type it
- COMPREPLY=()
- elif [[ $cword -eq 4 && "$cur" == -* ]]; then
- # Complete --keygen option
- COMPREPLY=($(compgen -W "--keygen" -- "$cur"))
- fi
- ;;
- "-"|"rm")
- if [[ $cword -eq 3 ]]; then
- local accounts
- accounts=$($cmd account list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$accounts" -- "$cur"))
- fi
- ;;
- esac
- return 0
- fi
-
- # Completion sheet
- if [[ "$subcmd" == "sheet" || "$subcmd" == "sh" ]]; then
- if [[ $cword -eq 2 ]]; then
- COMPREPLY=($(compgen -W "$sheet_commands" -- "$cur"))
- return 0
- fi
-
- case "$subsubcmd" in
- # Use jv sheet list --raw --all/--other
- "use"|"drop")
- if [[ $cword -eq 3 ]]; then
- local sheets
- sheets=$($cmd sheet list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$sheets" -- "$cur"))
- fi
- ;;
- "make")
- if [[ $cword -eq 3 ]]; then
- local all_sheets
- all_sheets=$($cmd sheet list --all --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$all_sheets" -- "$cur"))
- fi
- ;;
- "align")
- if [[ $cword -eq 3 ]]; then
- local align_items="lost moved erased"
- local unsolved_items
- unsolved_items=$($cmd sheet align --unsolved --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$align_items $unsolved_items" -- "$cur"))
- elif [[ $cword -eq 4 ]]; then
- local item="${words[3]}"
- local align_operations=""
- local created_items
- created_items=$($cmd sheet align --created --raw 2>/dev/null)
-
- if [[ "$item" == "lost" ]]; then
- align_operations="confirm"
- elif [[ "$item" == lost:* ]]; then
- align_operations="confirm $created_items"
- elif [[ "$item" == "moved" || "$item" == moved:* ]]; then
- align_operations="local remote break"
- elif [[ "$item" == "erased" || "$item" == erased:* ]]; then
- align_operations="confirm"
- else
- align_operations="local remote confirm break $created_items"
- fi
-
- COMPREPLY=($(compgen -W "$align_operations" -- "$cur"))
- fi
- ;;
- esac
- return 0
- fi
-
- # Completion align
- if [[ "$subcmd" == "align" ]]; then
- if [[ $cword -eq 2 ]]; then
- local align_items="lost moved erased"
- local unsolved_items
- unsolved_items=$($cmd sheet align --unsolved --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$align_items $unsolved_items" -- "$cur"))
- elif [[ $cword -eq 3 ]]; then
- local item="${words[2]}"
- local align_operations=""
- local created_items
- created_items=$($cmd sheet align --created --raw 2>/dev/null)
-
- if [[ "$item" == "lost" ]]; then
- align_operations="confirm"
- elif [[ "$item" == lost:* ]]; then
- align_operations="confirm $created_items"
- elif [[ "$item" == "moved" || "$item" == moved:* ]]; then
- align_operations="local remote break"
- elif [[ "$item" == "erased" || "$item" == erased:* ]]; then
- align_operations="confirm"
- else
- align_operations="local remote confirm break $created_items"
- fi
-
- COMPREPLY=($(compgen -W "$align_operations" -- "$cur"))
- fi
- return 0
- fi
-
- # Completion share
- if [[ "$subcmd" == "share" ]]; then
- if [[ $cword -eq 2 ]]; then
- # First parameter: list, see, jv share list --raw results, or files
- local share_list
- share_list=$($cmd share list --raw 2>/dev/null)
- local first_param_options="list see $share_list"
- COMPREPLY=($(compgen -W "$first_param_options" -f -- "$cur"))
- elif [[ $cword -eq 3 ]]; then
- # Second parameter: depends on first parameter
- local first_param="${words[2]}"
-
- if [[ "$first_param" == "list" ]]; then
- # list -> nothing
- COMPREPLY=()
- elif [[ "$first_param" == "see" ]]; then
- # see -> jv share list --raw results
- local share_list
- share_list=$($cmd share list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$share_list" -- "$cur"))
- elif [[ "$first_param" == *"@"* ]]; then
- # Contains "@" (shareid) -> show options
- COMPREPLY=($(compgen -W "--safe --overwrite --skip --reject" -- "$cur"))
- else
- # File input -> show jv sheet list --all --raw results
- local all_sheets
- all_sheets=$($cmd sheet list --all --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$all_sheets" -- "$cur"))
- fi
- fi
- # Third parameter: no completion
- return 0
- fi
-
- # Completion login
- if [[ "$subcmd" == "login" ]]; then
- if [[ $cword -eq 2 ]]; then
- local accounts
- accounts=$($cmd account list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$accounts" -- "$cur"))
- elif [[ $cword -eq 3 ]]; then
- local ip_history
- ip_history=$($cmd _ip_history 2>/dev/null)
- COMPREPLY=($(compgen -W "$ip_history" -- "$cur"))
- fi
- return 0
- fi
-
- # Completion direct
- if [[ "$subcmd" == "direct" ]]; then
- if [[ $cword -eq 2 ]]; then
- local ip_history
- ip_history=$($cmd _ip_history 2>/dev/null)
- COMPREPLY=($(compgen -W "$ip_history" -- "$cur"))
- fi
- return 0
- fi
-
- # Completion info
- if [[ "$subcmd" == "info" ]]; then
- if [[ $cword -eq 2 ]]; then
- COMPREPLY=($(compgen -f -- "$cur"))
- fi
- return 0
- fi
-
- # aliases
- case "$subcmd" in
- "as")
- if [[ $cword -eq 2 ]]; then
- local accounts
- accounts=$($cmd account list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$accounts" -- "$cur"))
- fi
- ;;
- "use")
- if [[ $cword -eq 2 ]]; then
- local sheets
- sheets=$($cmd sheet list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$sheets" -- "$cur"))
- fi
- ;;
- "make")
- if [[ $cword -eq 2 ]]; then
- local all_sheets
- all_sheets=$($cmd sheet list --all --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$all_sheets" -- "$cur"))
- fi
- ;;
- "drop")
- if [[ $cword -eq 2 ]]; then
- local sheets
- sheets=$($cmd sheet list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$sheets" -- "$cur"))
- fi
- ;;
- "docs")
- if [[ $cword -eq 2 ]]; then
- local docs
- docs=$($cmd docs list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$docs" -- "$cur"))
- fi
- ;;
- "move"|"mv")
- COMPREPLY=($(compgen -f -- "$cur"))
- ;;
- "track"|"hold"|"throw")
- COMPREPLY=($(compgen -f -- "$cur"))
- ;;
- esac
-}
-
-complete -F _jv_completion jv
diff --git a/scripts/deploy/completions/bash/completion_jvv.sh b/scripts/deploy/completions/bash/completion_jvv.sh
deleted file mode 100755
index ce5668b..0000000
--- a/scripts/deploy/completions/bash/completion_jvv.sh
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/bash
-# The JustEnoughVCS CommandLine Completion
-
-_jvv_completion() {
- local cur prev words cword
- COMPREPLY=()
- cur="${COMP_WORDS[COMP_CWORD]}"
- prev="${COMP_WORDS[COMP_CWORD-1]}"
- words=("${COMP_WORDS[@]}")
- cword=$COMP_CWORD
-
- # Current
- local cmd="${words[0]}"
- local subcmd="${words[1]}"
- local subsubcmd="${words[2]}"
-
- # Subcommands
- local base_commands="create init here member service listen members -c -i -H -m -l -M"
-
- # Subcommands - Member
- local member_commands="register remove list help + - ls"
-
- # Subcommands - Service
- local service_commands="listen help"
-
- # Completion subcommands
- if [[ $cword -eq 1 ]]; then
- COMPREPLY=($(compgen -W "$base_commands" -- "$cur"))
- return 0
- fi
-
- # Completion member
- if [[ "$subcmd" == "member" || "$subcmd" == "-m" ]]; then
- if [[ $cword -eq 2 ]]; then
- COMPREPLY=($(compgen -W "$member_commands" -- "$cur"))
- return 0
- fi
-
- case "$subsubcmd" in
- "remove"|"-")
- if [[ $cword -eq 3 ]]; then
- # Use jvv member list --raw
- local members
- members=$($cmd member list --raw 2>/dev/null)
- COMPREPLY=($(compgen -W "$members" -- "$cur"))
- fi
- ;;
- esac
- return 0
- fi
-
- # Completion service
- if [[ "$subcmd" == "service" ]]; then
- if [[ $cword -eq 2 ]]; then
- COMPREPLY=($(compgen -W "$service_commands" -- "$cur"))
- return 0
- fi
- return 0
- fi
-
- # aliases
- case "$subcmd" in
- "-m")
- if [[ $cword -eq 2 ]]; then
- COMPREPLY=($(compgen -W "$member_commands" -- "$cur"))
- fi
- ;;
- "listen"|"-l")
- # listen command has no arguments to complete
- ;;
- "members"|"-M")
- # members command has no arguments to complete
- ;;
- esac
-}
-
-# Register completion function
-complete -F _jvv_completion jvv
diff --git a/scripts/deploy/completions/fish.fish b/scripts/deploy/completions/fish.fish
new file mode 100644
index 0000000..2904495
--- /dev/null
+++ b/scripts/deploy/completions/fish.fish
@@ -0,0 +1,43 @@
+#!/usr/bin/env fish
+function __jvn_fish_complete
+ set -l cmdline (commandline -opc)
+ set -l buffer (commandline -b)
+ set -l cursor (commandline -C)
+
+ set -l current_word ""
+ set -l previous_word ""
+ set -l word_index 0
+ set -l char_count 0
+
+ for i in (seq (count $cmdline))
+ set word $cmdline[$i]
+ set char_count (math $char_count + (string length "$word") + 1)
+
+ if test $cursor -le $char_count
+ set word_index $i
+ set current_word $word
+ if test $i -gt 1
+ set previous_word $cmdline[(math $i - 1)]
+ end
+ break
+ end
+ end
+
+ set -l args \
+ -f "$buffer" \
+ -C "$cursor" \
+ -w "$current_word" \
+ -p "$previous_word" \
+ -c "$cmdline[1]" \
+ -i "$word_index" \
+ -a $cmdline
+
+ set -l output (jvn_comp $args 2>/dev/null)
+ if test "$output" = "_file_"
+ __fish_complete_path "$current_word"
+ else
+ printf "%s\n" $output
+ end
+end
+
+complete -c jvn -a '(__jvn_fish_complete)'
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, $_)
+ }
+ }
+}
diff --git a/scripts/deploy/completions/powershell/completion_jv.ps1 b/scripts/deploy/completions/powershell/completion_jv.ps1
deleted file mode 100644
index 84ba01a..0000000
--- a/scripts/deploy/completions/powershell/completion_jv.ps1
+++ /dev/null
@@ -1,250 +0,0 @@
-# The JustEnoughVCS CommandLine Completion
-
-Register-ArgumentCompleter -Native -CommandName jv -ScriptBlock {
- param($wordToComplete, $commandAst, $cursorPosition)
-
- $words = $commandAst.CommandElements | ForEach-Object { $_.ToString() }
- $currentIndex = $words.IndexOf($wordToComplete)
- if ($currentIndex -lt 0) { $currentIndex = $words.Count }
-
- $cmd = "jv"
- $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", "direct", "unstain", "account", "update",
- "sheet", "status", "here", "move", "mv", "docs", "exit", "use", "sheets", "accounts",
- "as", "make", "drop", "track", "hold", "throw", "login",
- "jump", "align", "info", "share"
- )
-
- # Account subcommands
- $accountCommands = @("list", "as", "add", "remove", "movekey", "mvkey", "mvk", "genpub", "help")
-
- # Sheet subcommands
- $sheetCommands = @("list", "use", "exit", "make", "drop", "help", "align")
-
- # Completion for main command
- if ($currentIndex -eq 1) {
- return $baseCommands | Where-Object { $_ -like "$wordToComplete*" }
- }
-
- # Completion for account command
- if ($subcmd -eq "account" -or $subcmd -eq "acc") {
- if ($currentIndex -eq 2) {
- return $accountCommands | Where-Object { $_ -like "$wordToComplete*" }
- }
-
- switch ($subsubcmd) {
- { @("as", "remove", "mvkey", "mvk", "movekey", "genpub") -contains $_ } {
- if ($currentIndex -eq 3) {
- $accounts = & $cmd account list --raw 2>$null
- return $accounts | Where-Object { $_ -like "$wordToComplete*" }
- } elseif ($currentIndex -eq 4 -and (@("mvkey", "mvk", "movekey", "genpub") -contains $subsubcmd)) {
- # File completion for key files
- return Get-ChildItem -Name -File -Path "." | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- "add" {
- if ($currentIndex -eq 3) {
- # No completion for account name
- return @()
- } elseif ($currentIndex -eq 4 -and $wordToComplete.StartsWith("-")) {
- # Complete --keygen option
- if ("--keygen" -like "$wordToComplete*") {
- return "--keygen"
- }
- }
- }
- { @("-", "rm") -contains $_ } {
- if ($currentIndex -eq 3) {
- $accounts = & $cmd account list --raw 2>$null
- return $accounts | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- }
- return @()
- }
-
- # Completion for sheet command
- if ($subcmd -eq "sheet" -or $subcmd -eq "sh") {
- if ($currentIndex -eq 2) {
- return $sheetCommands | Where-Object { $_ -like "$wordToComplete*" }
- }
-
- switch ($subsubcmd) {
- { @("use", "drop") -contains $_ } {
- if ($currentIndex -eq 3) {
- $sheets = & $cmd sheet list --raw 2>$null
- return $sheets | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- "make" {
- if ($currentIndex -eq 3) {
- $allSheets = & $cmd sheet list --all --raw 2>$null
- return $allSheets | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- "align" {
- if ($currentIndex -eq 3) {
- $alignItems = @("lost", "moved", "erased")
- $unsolvedItems = & $cmd sheet align --unsolved --raw 2>$null
- $completions = $alignItems + $unsolvedItems
- return $completions | Where-Object { $_ -like "$wordToComplete*" }
- } elseif ($currentIndex -eq 4) {
- $item = $words[3]
- $alignOperations = @()
- $createdItems = & $cmd sheet align --created --raw 2>$null
-
- if ($item -eq "lost") {
- $alignOperations = @("confirm")
- } elseif ($item -like "lost:*") {
- $alignOperations = @("confirm") + $createdItems
- } elseif ($item -eq "moved" -or $item -like "moved:*") {
- $alignOperations = @("local", "remote", "break")
- } elseif ($item -eq "erased" -or $item -like "erased:*") {
- $alignOperations = @("confirm")
- } else {
- $alignOperations = @("local", "remote", "confirm", "break") + $createdItems
- }
-
- return $alignOperations | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- }
- return @()
- }
-
- # Completion for align command
- if ($subcmd -eq "align") {
- if ($currentIndex -eq 2) {
- $alignItems = @("lost", "moved", "erased")
- $unsolvedItems = & $cmd sheet align --unsolved --raw 2>$null
- $completions = $alignItems + $unsolvedItems
- return $completions | Where-Object { $_ -like "$wordToComplete*" }
- } elseif ($currentIndex -eq 3) {
- $item = $words[2]
- $alignOperations = @()
- $createdItems = & $cmd sheet align --created --raw 2>$null
-
- if ($item -eq "lost") {
- $alignOperations = @("confirm")
- } elseif ($item -like "lost:*") {
- $alignOperations = @("confirm") + $createdItems
- } elseif ($item -eq "moved" -or $item -like "moved:*") {
- $alignOperations = @("local", "remote", "break")
- } elseif ($item -eq "erased" -or $item -like "erased:*") {
- $alignOperations = @("confirm")
- } else {
- $alignOperations = @("local", "remote", "confirm", "break") + $createdItems
- }
-
- return $alignOperations | Where-Object { $_ -like "$wordToComplete*" }
- }
- return @()
- }
-
- # Completion for login command
- if ($subcmd -eq "login") {
- if ($currentIndex -eq 2) {
- $accounts = & $cmd account list --raw 2>$null
- return $accounts | Where-Object { $_ -like "$wordToComplete*" }
- } elseif ($currentIndex -eq 3) {
- $ipHistory = & $cmd _ip_history 2>$null
- return $ipHistory | Where-Object { $_ -like "$wordToComplete*" }
- }
- return @()
- }
-
- # Completion for direct command
- if ($subcmd -eq "direct") {
- if ($currentIndex -eq 2) {
- $ipHistory = & $cmd _ip_history 2>$null
- return $ipHistory | Where-Object { $_ -like "$wordToComplete*" }
- }
- return @()
- }
-
- # Completion for info command
- if ($subcmd -eq "info") {
- if ($currentIndex -eq 2) {
- # File completion for the file argument
- return Get-ChildItem -Name -File -Path "." | Where-Object { $_ -like "$wordToComplete*" }
- }
- return @()
- }
-
- # Completion for share command
- if ($subcmd -eq "share") {
- if ($currentIndex -eq 2) {
- # First parameter: list, see, jv share list --raw results, or files in current directory
- $staticOptions = @("list", "see")
- $shareList = & $cmd share list --raw 2>$null
- $files = Get-ChildItem -Name -File -Path "." 2>$null
- $completions = $staticOptions + $shareList + $files
- return $completions | Where-Object { $_ -like "$wordToComplete*" }
- } elseif ($currentIndex -eq 3) {
- # Second parameter: depends on the first parameter
- $firstParam = $words[2]
- if ($firstParam -eq "list") {
- # list -> nothing
- return @()
- } elseif ($firstParam -eq "see") {
- # see -> jv share list --raw results
- $shareList = & $cmd share list --raw 2>$null
- return $shareList | Where-Object { $_ -like "$wordToComplete*" }
- } elseif ($firstParam -like "*@*") {
- # Contains "@" (shareid) -> show options
- $options = @("--safe", "--overwrite", "--skip", "--reject")
- return $options | Where-Object { $_ -like "$wordToComplete*" }
- } else {
- # Otherwise, assume it's a file -> show jv sheet list --all --raw results
- $allSheets = & $cmd sheet list --all --raw 2>$null
- return $allSheets | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- # Third parameter: no completion
- return @()
- }
-
- # Aliases completion
- switch ($subcmd) {
- "as" {
- if ($currentIndex -eq 2) {
- $accounts = & $cmd account list --raw 2>$null
- return $accounts | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- "use" {
- if ($currentIndex -eq 2) {
- $sheets = & $cmd sheet list --raw 2>$null
- return $sheets | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- "make" {
- if ($currentIndex -eq 2) {
- $allSheets = & $cmd sheet list --all --raw 2>$null
- return $allSheets | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- "drop" {
- if ($currentIndex -eq 2) {
- $sheets = & $cmd sheet list --raw 2>$null
- return $sheets | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- "docs" {
- if ($currentIndex -eq 2) {
- $docs = & $cmd docs list --raw 2>$null
- return $docs | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
- { @("move", "mv", "track", "hold", "throw") -contains $_ } {
- # File completion for file operations
- return Get-ChildItem -Name -File -Path "." | Where-Object { $_ -like "$wordToComplete*" }
- }
- }
-
- return @()
-}
diff --git a/scripts/deploy/completions/powershell/completion_jvv.ps1 b/scripts/deploy/completions/powershell/completion_jvv.ps1
deleted file mode 100644
index fa773c0..0000000
--- a/scripts/deploy/completions/powershell/completion_jvv.ps1
+++ /dev/null
@@ -1,67 +0,0 @@
-# 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 @()
-}
diff --git a/scripts/deploy/completions/zsh.sh b/scripts/deploy/completions/zsh.sh
new file mode 100644
index 0000000..2b2a96b
--- /dev/null
+++ b/scripts/deploy/completions/zsh.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env zsh
+_jvn_completion() {
+ local -a args
+ local suggestions
+
+ local buffer="$BUFFER"
+ local cursor="$CURSOR"
+ local current_word="${words[$CURRENT]}"
+ local previous_word=""
+ local command_name="${words[1]}"
+ local word_index="$CURRENT"
+
+ if [[ $CURRENT -gt 1 ]]; then
+ previous_word="${words[$((CURRENT-1))]}"
+ fi
+
+ args=(
+ -f "$buffer"
+ -C "$cursor"
+ -w "$current_word"
+ -p "$previous_word"
+ -c "$command_name"
+ -i "$word_index"
+ -a "${words[@]}"
+ )
+
+ suggestions=$(jvn_comp "${args[@]}" 2>/dev/null)
+
+ if [[ $? -eq 0 ]] && [[ -n "$suggestions" ]]; then
+ local -a completions
+ completions=(${(f)suggestions})
+
+ if [[ "${completions[1]}" == "_file_" ]]; then
+ shift completions
+ _files
+ elif (( $+functions[_describe] )); then
+ _describe 'jvn commands' completions
+ else
+ compadd -a completions
+ fi
+ fi
+}
+
+compdef _jvn_completion jvn
+
+if [[ $? -ne 0 ]]; then
+ compctl -K _jvn_completion jvn
+fi