From 72f80ea51f25256d0c463c2f3dc3d8670cfc4634 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 14 Mar 2026 22:12:30 +0800 Subject: Add shell completions for new jvn CLI --- scripts/deploy/completions/bash.sh | 65 +++++ scripts/deploy/completions/bash/completion_jv.sh | 272 --------------------- scripts/deploy/completions/bash/completion_jvv.sh | 78 ------ scripts/deploy/completions/fish.fish | 43 ++++ scripts/deploy/completions/powershell.ps1 | 42 ++++ .../completions/powershell/completion_jv.ps1 | 250 ------------------- .../completions/powershell/completion_jvv.ps1 | 67 ----- scripts/deploy/completions/zsh.sh | 48 ++++ scripts/deploy/jv_cli.ps1 | 4 +- scripts/deploy/jv_cli.sh | 8 +- scripts/deploy/jvn.ps1 | 13 + scripts/deploy/jvn.sh | 25 ++ .../legacy_completions/bash/completion_jv.sh | 272 +++++++++++++++++++++ .../legacy_completions/bash/completion_jvv.sh | 78 ++++++ .../powershell/completion_jv.ps1 | 250 +++++++++++++++++++ .../powershell/completion_jvv.ps1 | 67 +++++ .../deploy/legacy_zsh_support/how_to_install.md | 61 +++++ scripts/deploy/legacy_zsh_support/install.sh | 3 + scripts/deploy/legacy_zsh_support/jvcs.plugin.zsh | 156 ++++++++++++ scripts/deploy/zsh_support/how_to_install.md | 61 ----- scripts/deploy/zsh_support/install.sh | 3 - scripts/deploy/zsh_support/jvcs.plugin.zsh | 156 ------------ 22 files changed, 1129 insertions(+), 893 deletions(-) create mode 100644 scripts/deploy/completions/bash.sh delete mode 100755 scripts/deploy/completions/bash/completion_jv.sh delete mode 100755 scripts/deploy/completions/bash/completion_jvv.sh create mode 100644 scripts/deploy/completions/fish.fish create mode 100644 scripts/deploy/completions/powershell.ps1 delete mode 100644 scripts/deploy/completions/powershell/completion_jv.ps1 delete mode 100644 scripts/deploy/completions/powershell/completion_jvv.ps1 create mode 100644 scripts/deploy/completions/zsh.sh create mode 100644 scripts/deploy/jvn.ps1 create mode 100644 scripts/deploy/jvn.sh create mode 100755 scripts/deploy/legacy_completions/bash/completion_jv.sh create mode 100755 scripts/deploy/legacy_completions/bash/completion_jvv.sh create mode 100644 scripts/deploy/legacy_completions/powershell/completion_jv.ps1 create mode 100644 scripts/deploy/legacy_completions/powershell/completion_jvv.ps1 create mode 100644 scripts/deploy/legacy_zsh_support/how_to_install.md create mode 100755 scripts/deploy/legacy_zsh_support/install.sh create mode 100644 scripts/deploy/legacy_zsh_support/jvcs.plugin.zsh delete mode 100644 scripts/deploy/zsh_support/how_to_install.md delete mode 100755 scripts/deploy/zsh_support/install.sh delete mode 100644 scripts/deploy/zsh_support/jvcs.plugin.zsh (limited to 'scripts/deploy') 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 diff --git a/scripts/deploy/jv_cli.ps1 b/scripts/deploy/jv_cli.ps1 index 2761137..3de330a 100644 --- a/scripts/deploy/jv_cli.ps1 +++ b/scripts/deploy/jv_cli.ps1 @@ -47,10 +47,10 @@ Set-Alias jmv jmv ### COMPLETION ### ################## -if (Test-Path "$SCRIPT_DIR\comp\jv.ps1") { +if (Test-Path "$SCRIPT_DIR\_legacy\comp\jv.ps1") { . "$SCRIPT_DIR\comp\jv.ps1" } -if (Test-Path "$SCRIPT_DIR\comp\jvv.ps1") { +if (Test-Path "$SCRIPT_DIR\_legacy\comp\jvv.ps1") { . "$SCRIPT_DIR\comp\jvv.ps1" } diff --git a/scripts/deploy/jv_cli.sh b/scripts/deploy/jv_cli.sh index 80ff757..b5212af 100755 --- a/scripts/deploy/jv_cli.sh +++ b/scripts/deploy/jv_cli.sh @@ -58,11 +58,11 @@ alias jvu='jv update' ### COMPLETION ### ################## -if [ -f "$SCRIPT_DIR/comp/jv.sh" ]; then - source "$SCRIPT_DIR/comp/jv.sh" +if [ -f "$SCRIPT_DIR/_legacy/comp/jv.sh" ]; then + source "$SCRIPT_DIR/_legacy/comp/jv.sh" fi -if [ -f "$SCRIPT_DIR/comp/jvv.sh" ]; then - source "$SCRIPT_DIR/comp/jvv.sh" +if [ -f "$SCRIPT_DIR/_legacy/comp/jvv.sh" ]; then + source "$SCRIPT_DIR/_legacy/comp/jvv.sh" fi ################## diff --git a/scripts/deploy/jvn.ps1 b/scripts/deploy/jvn.ps1 new file mode 100644 index 0000000..64959d0 --- /dev/null +++ b/scripts/deploy/jvn.ps1 @@ -0,0 +1,13 @@ +$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition + +# Completion +$completionScript = Join-Path $SCRIPT_DIR "comp\jvn_pwsl.ps1" +if (Test-Path $completionScript) { + . $completionScript +} + +# Envirement +$binPath = Join-Path $SCRIPT_DIR "bin" +if (Test-Path $binPath) { + $env:PATH = "$binPath;$env:PATH" +} diff --git a/scripts/deploy/jvn.sh b/scripts/deploy/jvn.sh new file mode 100644 index 0000000..25c6ad5 --- /dev/null +++ b/scripts/deploy/jvn.sh @@ -0,0 +1,25 @@ +#!bin/bash +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" + +# Completion script +if [ -n "$BASH_VERSION" ]; then + # Bash + if [ -f "$SCRIPT_DIR/comp/jvn_bash.sh" ]; then + source "$SCRIPT_DIR/comp/jvn_bash.sh" + fi +elif [ -n "$ZSH_VERSION" ]; then + # Zsh + if [ -f "$SCRIPT_DIR/comp/jvn_zsh.sh" ]; then + source "$SCRIPT_DIR/comp/jvn_zsh.sh" + fi +elif [ -n "$FISH_VERSION" ]; then + # Fish + if [ -f "$SCRIPT_DIR/comp/jvn_fish.fish" ]; then + source "$SCRIPT_DIR/comp/jvn_fish.fish" + fi +fi + +# Envirement +if [ -d "$SCRIPT_DIR/bin" ]; then + export PATH="$SCRIPT_DIR/bin:$PATH" +fi diff --git a/scripts/deploy/legacy_completions/bash/completion_jv.sh b/scripts/deploy/legacy_completions/bash/completion_jv.sh new file mode 100755 index 0000000..364df9d --- /dev/null +++ b/scripts/deploy/legacy_completions/bash/completion_jv.sh @@ -0,0 +1,272 @@ +#!/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/legacy_completions/bash/completion_jvv.sh b/scripts/deploy/legacy_completions/bash/completion_jvv.sh new file mode 100755 index 0000000..ce5668b --- /dev/null +++ b/scripts/deploy/legacy_completions/bash/completion_jvv.sh @@ -0,0 +1,78 @@ +#!/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/legacy_completions/powershell/completion_jv.ps1 b/scripts/deploy/legacy_completions/powershell/completion_jv.ps1 new file mode 100644 index 0000000..84ba01a --- /dev/null +++ b/scripts/deploy/legacy_completions/powershell/completion_jv.ps1 @@ -0,0 +1,250 @@ +# 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/legacy_completions/powershell/completion_jvv.ps1 b/scripts/deploy/legacy_completions/powershell/completion_jvv.ps1 new file mode 100644 index 0000000..fa773c0 --- /dev/null +++ b/scripts/deploy/legacy_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 @() +} diff --git a/scripts/deploy/legacy_zsh_support/how_to_install.md b/scripts/deploy/legacy_zsh_support/how_to_install.md new file mode 100644 index 0000000..343ea7b --- /dev/null +++ b/scripts/deploy/legacy_zsh_support/how_to_install.md @@ -0,0 +1,61 @@ +# How to Install + +Before installing, please ensure: + +* [Oh My Zsh](https://ohmyz.sh/) is installed. +* Your current shell is **Zsh**. + +--- + +## Install the Zsh Plugin + +In your terminal, run: + +```bash +./install.sh +``` + +This script will install JVCS's Zsh support files locally and prepare the prompt segment definitions for use by your theme. + +--- + +## Configure Your Zsh Theme + +Open your current Zsh theme file (e.g., `~/.oh-my-zsh/themes/xxx.zsh-theme`) and paste the following content in an appropriate location: + +```bash +# ----------------------------------------------------- # +# DISPLAY_LEVEL +# FULL = 127.0.0.1:25331/account/sheet +# NORMAL = account/sheet +# SHORT = sheet +JVCS_VIEW='NORMAL' + +# Customizable prompt segment elements +JVCS_PREFIX='[' +JVCS_SPLIT='/' +JVCS_SUFFIX=']' + +# JVCS_PROMPT_SEGMENT default style: +# [your_account/your_sheet] + +# Append JVCS prompt segment +PROMPT+='${JVCS_PROMPT_SEGMENT}' +# ----------------------------------------------------- # +``` + +After saving, reload your terminal, or run: + +```bash +source ~/.zshrc +``` + +--- + +## Notes + +* `JVCS_VIEW` controls the view level displayed in the prompt. +* `JVCS_PREFIX / SPLIT / SUFFIX` are used to customize the appearance. +* `JVCS_PROMPT_SEGMENT` is only responsible for displaying the status and does not execute any logic. + +No further configuration is required. diff --git a/scripts/deploy/legacy_zsh_support/install.sh b/scripts/deploy/legacy_zsh_support/install.sh new file mode 100755 index 0000000..aa92952 --- /dev/null +++ b/scripts/deploy/legacy_zsh_support/install.sh @@ -0,0 +1,3 @@ +#!/bin/zsh +cd "$(dirname "$0")" +cp jvcs.plugin.zsh ~/.oh-my-zsh/custom/plugins/jvcs/jvcs.plugin.zsh diff --git a/scripts/deploy/legacy_zsh_support/jvcs.plugin.zsh b/scripts/deploy/legacy_zsh_support/jvcs.plugin.zsh new file mode 100644 index 0000000..ff3f213 --- /dev/null +++ b/scripts/deploy/legacy_zsh_support/jvcs.plugin.zsh @@ -0,0 +1,156 @@ +# ████████ ████████ +# ██▒▒▒▒▒▒▒▒██ ██▒▒▒▒▒▒▒▒██ +# ██ ▒▒██ ██▒▒ ██ █████ ██ ██ ██████ █████ +# ██ ▒▒████████▒▒ ██ ▒▒▒██ ██ ██ ██████ ██████ +# ██ ▒▒▒▒▒▒▒▒ ██ ██ ██ ██ ███▒▒▒█ █▒▒▒▒█ +# ██ ██ ██ ██ ██ ███ ▒ ████ ▒ +# ██ ██ ██ ██ ██ ███ ▒████ +# ██ ████ ████ ██ ██ ▒██ ██▒ ███ ▒▒▒██ +# ██ ████ ████ ██ █ ██ ██ ██ ███ █ ██ ██ +# ██ ████ ████ ██ █ ██ ▒████▒ ▒██████ ██████ +# ██ ▒▒▒▒ ▒▒▒▒ █ ██ ▒████ ▒██▒ ██████ ▒████▒ +# ██ ██ ██ ▒▒▒▒ ▒▒ ▒▒▒▒▒▒ ▒▒▒▒ +# ██ ██████████ ██ +# ██ ██ JustEnoughVCS CommandLine +# ████████████████████████████████ Zsh Plugin +# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ + +autoload -Uz add-zsh-hook + +################## +### APPEARANCE ### +################## + +JVCS_VIEW='NORMAL' +JVCS_PREFIX='[' +JVCS_SPLIT='/' +JVCS_SUFFIX=']' + +################### +### THEME READS ### +################### + +JVCS_PROMPT_SEGMENT='' + +###################### +### INTERNAL STATE ### +###################### + +JVCS_DISPLAY='' +JVCS_WS='' +JVCS_ACCOUNT='' +JVCS_SHEET='' +JVCS_UPSTREAM='' + +################### +### STATE LAYER ### +################### + +jvcs_read_state() { + if command -v jv &>/dev/null; then + JVCS_WS="$(jv _workspace_dir 2>/dev/null)" + JVCS_ACCOUNT="$(jv _account 2>/dev/null)" + JVCS_SHEET="$(jv _sheet 2>/dev/null)" + JVCS_UPSTREAM="$(jv _upstream 2>/dev/null)" + else + JVCS_WS='' + JVCS_ACCOUNT='' + JVCS_SHEET='' + JVCS_UPSTREAM='' + fi +} + +################## +### VIEW LAYER ### +################## + +jvcs_compute_view() { + # Must be in a Workspace, otherwise do not display + if [[ -z "$JVCS_WS" ]]; then + JVCS_DISPLAY='' + return + fi + JVCS_DISPLAY='1' +} + +#################### +### RENDER LAYER ### +#################### + +jvcs_render_prompt() { + # Only set prompt segment if display is enabled + if [[ -n "$JVCS_DISPLAY" ]]; then + case "$JVCS_VIEW" in + FULL) + JVCS_PROMPT_SEGMENT="%{$fg[white]%}${JVCS_PREFIX}${JVCS_UPSTREAM}${JVCS_SPLIT}${JVCS_ACCOUNT}${JVCS_SPLIT}${JVCS_SHEET}${JVCS_SUFFIX} %{$reset_color%}" + ;; + NORMAL) + JVCS_PROMPT_SEGMENT="%{$fg[white]%}${JVCS_PREFIX}${JVCS_ACCOUNT}${JVCS_SPLIT}${JVCS_SHEET}${JVCS_SUFFIX} %{$reset_color%}" + ;; + SHORT) + JVCS_PROMPT_SEGMENT="%{$fg[white]%}${JVCS_PREFIX}${JVCS_SHEET}${JVCS_SUFFIX} %{$reset_color%}" + ;; + *) + JVCS_PROMPT_SEGMENT='' + ;; + esac + else + JVCS_PROMPT_SEGMENT='' + fi +} + +#################### +### ORCHESTRATOR ### +#################### + +jvcs_update() { + jvcs_read_state + jvcs_compute_view + jvcs_render_prompt +} + +############# +### HOOKS ### +############# + +JVCS_NEED_REFRESH=0 + +jvcs_preexec() { + case "$1" in + jv\ status | \ + jv\ use* | \ + jv\ as* | \ + jv\ exit | \ + jv\ sheet\ use* | \ + jv\ sheet\ sheet\ exit | \ + jv\ account\ as*) + JVCS_NEED_REFRESH=1 + ;; + esac +} + +jvcs_precmd() { + [[ "$JVCS_NEED_REFRESH" -eq 1 ]] || return + JVCS_NEED_REFRESH=0 + jvcs_update +} + +jvcs_chpwd() { + jvcs_update +} + +add-zsh-hook preexec jvcs_preexec +add-zsh-hook precmd jvcs_precmd +add-zsh-hook chpwd jvcs_chpwd + +############################### +### FALLBACK INITIALIZATION ### +############################### + +jvcs_precmd_init() { + [[ -n "${JVCS_INITIALIZED:-}" ]] && return + JVCS_INITIALIZED=1 + jvcs_update +} + +add-zsh-hook precmd jvcs_precmd_init diff --git a/scripts/deploy/zsh_support/how_to_install.md b/scripts/deploy/zsh_support/how_to_install.md deleted file mode 100644 index 343ea7b..0000000 --- a/scripts/deploy/zsh_support/how_to_install.md +++ /dev/null @@ -1,61 +0,0 @@ -# How to Install - -Before installing, please ensure: - -* [Oh My Zsh](https://ohmyz.sh/) is installed. -* Your current shell is **Zsh**. - ---- - -## Install the Zsh Plugin - -In your terminal, run: - -```bash -./install.sh -``` - -This script will install JVCS's Zsh support files locally and prepare the prompt segment definitions for use by your theme. - ---- - -## Configure Your Zsh Theme - -Open your current Zsh theme file (e.g., `~/.oh-my-zsh/themes/xxx.zsh-theme`) and paste the following content in an appropriate location: - -```bash -# ----------------------------------------------------- # -# DISPLAY_LEVEL -# FULL = 127.0.0.1:25331/account/sheet -# NORMAL = account/sheet -# SHORT = sheet -JVCS_VIEW='NORMAL' - -# Customizable prompt segment elements -JVCS_PREFIX='[' -JVCS_SPLIT='/' -JVCS_SUFFIX=']' - -# JVCS_PROMPT_SEGMENT default style: -# [your_account/your_sheet] - -# Append JVCS prompt segment -PROMPT+='${JVCS_PROMPT_SEGMENT}' -# ----------------------------------------------------- # -``` - -After saving, reload your terminal, or run: - -```bash -source ~/.zshrc -``` - ---- - -## Notes - -* `JVCS_VIEW` controls the view level displayed in the prompt. -* `JVCS_PREFIX / SPLIT / SUFFIX` are used to customize the appearance. -* `JVCS_PROMPT_SEGMENT` is only responsible for displaying the status and does not execute any logic. - -No further configuration is required. diff --git a/scripts/deploy/zsh_support/install.sh b/scripts/deploy/zsh_support/install.sh deleted file mode 100755 index aa92952..0000000 --- a/scripts/deploy/zsh_support/install.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/zsh -cd "$(dirname "$0")" -cp jvcs.plugin.zsh ~/.oh-my-zsh/custom/plugins/jvcs/jvcs.plugin.zsh diff --git a/scripts/deploy/zsh_support/jvcs.plugin.zsh b/scripts/deploy/zsh_support/jvcs.plugin.zsh deleted file mode 100644 index ff3f213..0000000 --- a/scripts/deploy/zsh_support/jvcs.plugin.zsh +++ /dev/null @@ -1,156 +0,0 @@ -# ████████ ████████ -# ██▒▒▒▒▒▒▒▒██ ██▒▒▒▒▒▒▒▒██ -# ██ ▒▒██ ██▒▒ ██ █████ ██ ██ ██████ █████ -# ██ ▒▒████████▒▒ ██ ▒▒▒██ ██ ██ ██████ ██████ -# ██ ▒▒▒▒▒▒▒▒ ██ ██ ██ ██ ███▒▒▒█ █▒▒▒▒█ -# ██ ██ ██ ██ ██ ███ ▒ ████ ▒ -# ██ ██ ██ ██ ██ ███ ▒████ -# ██ ████ ████ ██ ██ ▒██ ██▒ ███ ▒▒▒██ -# ██ ████ ████ ██ █ ██ ██ ██ ███ █ ██ ██ -# ██ ████ ████ ██ █ ██ ▒████▒ ▒██████ ██████ -# ██ ▒▒▒▒ ▒▒▒▒ █ ██ ▒████ ▒██▒ ██████ ▒████▒ -# ██ ██ ██ ▒▒▒▒ ▒▒ ▒▒▒▒▒▒ ▒▒▒▒ -# ██ ██████████ ██ -# ██ ██ JustEnoughVCS CommandLine -# ████████████████████████████████ Zsh Plugin -# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ - -autoload -Uz add-zsh-hook - -################## -### APPEARANCE ### -################## - -JVCS_VIEW='NORMAL' -JVCS_PREFIX='[' -JVCS_SPLIT='/' -JVCS_SUFFIX=']' - -################### -### THEME READS ### -################### - -JVCS_PROMPT_SEGMENT='' - -###################### -### INTERNAL STATE ### -###################### - -JVCS_DISPLAY='' -JVCS_WS='' -JVCS_ACCOUNT='' -JVCS_SHEET='' -JVCS_UPSTREAM='' - -################### -### STATE LAYER ### -################### - -jvcs_read_state() { - if command -v jv &>/dev/null; then - JVCS_WS="$(jv _workspace_dir 2>/dev/null)" - JVCS_ACCOUNT="$(jv _account 2>/dev/null)" - JVCS_SHEET="$(jv _sheet 2>/dev/null)" - JVCS_UPSTREAM="$(jv _upstream 2>/dev/null)" - else - JVCS_WS='' - JVCS_ACCOUNT='' - JVCS_SHEET='' - JVCS_UPSTREAM='' - fi -} - -################## -### VIEW LAYER ### -################## - -jvcs_compute_view() { - # Must be in a Workspace, otherwise do not display - if [[ -z "$JVCS_WS" ]]; then - JVCS_DISPLAY='' - return - fi - JVCS_DISPLAY='1' -} - -#################### -### RENDER LAYER ### -#################### - -jvcs_render_prompt() { - # Only set prompt segment if display is enabled - if [[ -n "$JVCS_DISPLAY" ]]; then - case "$JVCS_VIEW" in - FULL) - JVCS_PROMPT_SEGMENT="%{$fg[white]%}${JVCS_PREFIX}${JVCS_UPSTREAM}${JVCS_SPLIT}${JVCS_ACCOUNT}${JVCS_SPLIT}${JVCS_SHEET}${JVCS_SUFFIX} %{$reset_color%}" - ;; - NORMAL) - JVCS_PROMPT_SEGMENT="%{$fg[white]%}${JVCS_PREFIX}${JVCS_ACCOUNT}${JVCS_SPLIT}${JVCS_SHEET}${JVCS_SUFFIX} %{$reset_color%}" - ;; - SHORT) - JVCS_PROMPT_SEGMENT="%{$fg[white]%}${JVCS_PREFIX}${JVCS_SHEET}${JVCS_SUFFIX} %{$reset_color%}" - ;; - *) - JVCS_PROMPT_SEGMENT='' - ;; - esac - else - JVCS_PROMPT_SEGMENT='' - fi -} - -#################### -### ORCHESTRATOR ### -#################### - -jvcs_update() { - jvcs_read_state - jvcs_compute_view - jvcs_render_prompt -} - -############# -### HOOKS ### -############# - -JVCS_NEED_REFRESH=0 - -jvcs_preexec() { - case "$1" in - jv\ status | \ - jv\ use* | \ - jv\ as* | \ - jv\ exit | \ - jv\ sheet\ use* | \ - jv\ sheet\ sheet\ exit | \ - jv\ account\ as*) - JVCS_NEED_REFRESH=1 - ;; - esac -} - -jvcs_precmd() { - [[ "$JVCS_NEED_REFRESH" -eq 1 ]] || return - JVCS_NEED_REFRESH=0 - jvcs_update -} - -jvcs_chpwd() { - jvcs_update -} - -add-zsh-hook preexec jvcs_preexec -add-zsh-hook precmd jvcs_precmd -add-zsh-hook chpwd jvcs_chpwd - -############################### -### FALLBACK INITIALIZATION ### -############################### - -jvcs_precmd_init() { - [[ -n "${JVCS_INITIALIZED:-}" ]] && return - JVCS_INITIALIZED=1 - jvcs_update -} - -add-zsh-hook precmd jvcs_precmd_init -- cgit