summaryrefslogtreecommitdiff
path: root/scripts/deploy/completions/fish.fish
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-25 13:22:16 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-25 13:22:16 +0800
commitfece037f453006c83c45825e3649495180eb30c9 (patch)
tree5ce6f59c1daf525eeb73ce54393b9cd572774a53 /scripts/deploy/completions/fish.fish
parent8f69598f6abfb2b3db076a15fed85c9c186ccbde (diff)
Split Unix completion script entry into separate bash/zsh/fish versions
Diffstat (limited to 'scripts/deploy/completions/fish.fish')
-rw-r--r--scripts/deploy/completions/fish.fish76
1 files changed, 61 insertions, 15 deletions
diff --git a/scripts/deploy/completions/fish.fish b/scripts/deploy/completions/fish.fish
index 558b602..eb2c2df 100644
--- a/scripts/deploy/completions/fish.fish
+++ b/scripts/deploy/completions/fish.fish
@@ -4,6 +4,7 @@ function __jvn_fish_complete
set -l buffer (commandline -b)
set -l cursor (commandline -C)
+ # Calculate current word and word index
set -l current_word ""
set -l previous_word ""
set -l word_index 0
@@ -11,7 +12,10 @@ function __jvn_fish_complete
for i in (seq (count $cmdline))
set word $cmdline[$i]
- set char_count (math $char_count + (string length "$word") + 1)
+ if test $i -gt 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
@@ -23,21 +27,63 @@ function __jvn_fish_complete
end
end
- set -l args \
- -f (string replace -a - ^ -- "$buffer") \
- -C "$cursor" \
- -w (string replace -a - ^ -- "$current_word") \
- -p (string replace -a - ^ -- "$previous_word") \
- -c "$cmdline[1]" \
- -i "$word_index" \
- -a (string replace -a - ^ -- "$cmdline")
-
- set -l output (jvn_comp $args 2>/dev/null)
- if test "$output" = "_file_"
- __fish_complete_path "$current_word"
+ # Handle cursor after last word
+ if test $word_index -eq 0 -a (count $cmdline) -gt 0
+ set word_index (count $cmdline)
+ set current_word ""
+ set previous_word $cmdline[-1]
+ end
+
+ # Ensure word_index is within bounds
+ if test $word_index -gt (count $cmdline)
+ set word_index (count $cmdline)
+ end
+
+ # Replace hyphens with carets for jvn_comp
+ set -l buffer_replaced (string replace -a "-" "^" -- "$buffer")
+ set -l current_word_replaced (string replace -a "-" "^" -- "$current_word")
+ set -l previous_word_replaced (string replace -a "-" "^" -- "$previous_word")
+
+ # Build args array
+ set -l args
+ set -a args -f "$buffer_replaced" -C "$cursor" -w "$current_word_replaced" -p "$previous_word_replaced"
+
+ if test (count $cmdline) -gt 0
+ set -a args -c "$cmdline[1]"
else
- printf "%s\n" $output
+ set -a args -c ""
+ end
+
+ set -a args -i "$word_index"
+
+ # Replace hyphens in all words
+ if test (count $cmdline) -gt 0
+ set -l all_words_replaced
+ for word in $cmdline
+ set -a all_words_replaced (string replace -a "-" "^" -- "$word")
+ end
+ set -a args -a $all_words_replaced
+ else
+ set -a args -a ""
+ end
+
+ # Call jvn_comp and handle output
+ set -l output
+ if not jvn_comp $args 2>/dev/null | read -z output
+ return
+ end
+
+ set -l trimmed_output (string trim -- "$output")
+ if test "$trimmed_output" = "_file_"
+ __fish_complete_path "$current_word"
+ return 0
+ else if test -n "$trimmed_output"
+ string split -n \n -- "$output" | while read -l line
+ test -n "$line" && echo "$line"
+ end
+ return 0
end
+ return 1
end
-complete -c jvn -a '(__jvn_fish_complete)'
+complete -c jvn -a '(__jvn_fish_complete)' -f