diff options
Diffstat (limited to 'scripts/deploy/completions')
| -rw-r--r-- | scripts/deploy/completions/bash.sh | 1 | ||||
| -rw-r--r-- | scripts/deploy/completions/fish.fish | 61 | ||||
| -rw-r--r-- | scripts/deploy/completions/powershell.ps1 | 1 | ||||
| -rw-r--r-- | scripts/deploy/completions/zsh.zsh | 26 |
4 files changed, 75 insertions, 14 deletions
diff --git a/scripts/deploy/completions/bash.sh b/scripts/deploy/completions/bash.sh index a9a3263..647b5bb 100644 --- a/scripts/deploy/completions/bash.sh +++ b/scripts/deploy/completions/bash.sh @@ -13,6 +13,7 @@ _jvn_bash_completion() { args+=(-p="${prev//-/^}") args+=(-c="${COMP_WORDS[0]//-/^}") args+=(-i="$word_index") + args+=(-F="bash") for word in "${COMP_WORDS[@]}"; do args+=(-a="${word//-/^}") diff --git a/scripts/deploy/completions/fish.fish b/scripts/deploy/completions/fish.fish index eb2c2df..cb31936 100644 --- a/scripts/deploy/completions/fish.fish +++ b/scripts/deploy/completions/fish.fish @@ -3,6 +3,7 @@ function __jvn_fish_complete set -l cmdline (commandline -opc) set -l buffer (commandline -b) set -l cursor (commandline -C) + set -l current_token (commandline -ct) # Calculate current word and word index set -l current_word "" @@ -10,27 +11,48 @@ function __jvn_fish_complete set -l word_index 0 set -l char_count 0 - for i in (seq (count $cmdline)) - set word $cmdline[$i] - if test $i -gt 1 - set char_count (math $char_count + 1) + set -l found false + if test -n "$current_token" + for i in (seq (count $cmdline)) + if test "$cmdline[$i]" = "$current_token" + set word_index $i + set current_word $current_token + if test $i -gt 1 + set previous_word $cmdline[(math $i - 1)] + end + set found true + break + end end - set char_count (math $char_count + (string length -- "$word")) + end - if test $cursor -le $char_count - set word_index $i - set current_word $word + if not $found + for i in (seq (count $cmdline)) + set word $cmdline[$i] if test $i -gt 1 - set previous_word $cmdline[(math $i - 1)] + set char_count (math $char_count + 1) + end + set char_count (math $char_count + (string length -- "$word")) + + 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 - break end end # Handle cursor after last word if test $word_index -eq 0 -a (count $cmdline) -gt 0 set word_index (count $cmdline) - set current_word "" + if test -n "$current_token" -a "$current_token" != "$cmdline[-1]" + set current_word $current_token + else + set current_word "" + end set previous_word $cmdline[-1] end @@ -62,11 +84,28 @@ function __jvn_fish_complete for word in $cmdline set -a all_words_replaced (string replace -a "-" "^" -- "$word") end + + if test -n "$current_token" -a "$current_word" = "$current_token" + set -l found_in_cmdline false + for word in $cmdline + if test "$word" = "$current_token" + set found_in_cmdline true + break + end + end + if not $found_in_cmdline -a $word_index -eq (math (count $cmdline) + 1) + set -a all_words_replaced (string replace -a "-" "^" -- "$current_token") + end + end + set -a args -a $all_words_replaced else set -a args -a "" end + # Add shell type argument + set -a args -F "fish" + # Call jvn_comp and handle output set -l output if not jvn_comp $args 2>/dev/null | read -z output diff --git a/scripts/deploy/completions/powershell.ps1 b/scripts/deploy/completions/powershell.ps1 index ec91038..e393e52 100644 --- a/scripts/deploy/completions/powershell.ps1 +++ b/scripts/deploy/completions/powershell.ps1 @@ -25,6 +25,7 @@ Register-ArgumentCompleter -CommandName jvn -ScriptBlock { "-c", $commandName "-i", ($words.Count - 1).ToString() "-a", ($words | ForEach-Object { $_ -replace '-', '^' }) + "-F", "powershell" ) $suggestions = jvn_comp $args 2>$null diff --git a/scripts/deploy/completions/zsh.zsh b/scripts/deploy/completions/zsh.zsh index dd1ff38..99ecd09 100644 --- a/scripts/deploy/completions/zsh.zsh +++ b/scripts/deploy/completions/zsh.zsh @@ -22,6 +22,7 @@ _jvn_completion() { -c "$command_name" -i "$word_index" -a "${(@)words//-/^}" + -F "zsh" ) suggestions=$(jvn_comp "${args[@]}" 2>/dev/null) @@ -33,10 +34,29 @@ _jvn_completion() { if [[ "${completions[1]}" == "_file_" ]]; then shift completions _files - elif (( $+functions[_describe] )); then - _describe 'jvn commands' completions else - compadd -a completions + local -a parsed_completions + for item in "${completions[@]}"; do + if [[ "$item" =~ '^([^$]+)\$\((.+)\)$' ]]; then + parsed_completions+=("${match[1]}:${match[2]}") + else + parsed_completions+=("$item") + fi + done + + if (( $+functions[_describe] )); then + _describe 'jvn commands' parsed_completions + else + local -a simple_completions + for item in "${parsed_completions[@]}"; do + if [[ "$item" =~ '^([^:]+):(.+)$' ]]; then + simple_completions+=("${match[1]}") + else + simple_completions+=("$item") + fi + done + compadd -a simple_completions + fi fi fi } |
