diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-26 15:55:10 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-26 15:55:10 +0800 |
| commit | fb2ffa849a2cf9251cc274ebea5daa9898579787 (patch) | |
| tree | 53b87ee60ba7c6ee7b001221855a6f3bff7e8526 /scripts/deploy/completions/fish.fish | |
| parent | 4cb7c2e91d7dbde32de31e6ab48683d60212ec1d (diff) | |
Add shell completion system with descriptions and i18n support
Diffstat (limited to 'scripts/deploy/completions/fish.fish')
| -rw-r--r-- | scripts/deploy/completions/fish.fish | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/scripts/deploy/completions/fish.fish b/scripts/deploy/completions/fish.fish index 45205a3..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,6 +84,20 @@ 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 "" |
