Skip to content

Commit 509b71f

Browse files
committed
Dropped tmux support for now, better completion handling
1 parent 156205d commit 509b71f

File tree

1 file changed

+12
-41
lines changed

1 file changed

+12
-41
lines changed

shell/completion.fish

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# / __/ / /_/ __/
55
# /_/ /___/_/ completion.fish
66
#
7-
# - $FZF_TMUX (default: 0)
8-
# - $FZF_TMUX_OPTS (default: empty)
97
# - $FZF_COMPLETION_TRIGGER (default: '**')
108
# - $FZF_COMPLETION_OPTS (default: empty)
119
# - $FZF_COMPLETION_PATH_OPTS (default: empty)
@@ -28,31 +26,11 @@ function fzf_completion_setup
2826
return 1
2927
end
3028

31-
function __fzf_completion_defaults
32-
# $argv[1]: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
33-
# $argv[2..]: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
34-
test -n "$FZF_TMUX_HEIGHT"; or set -l FZF_TMUX_HEIGHT 40%
35-
string join ' ' -- \
36-
"--height $FZF_TMUX_HEIGHT --min-height=20+ --bind=ctrl-z:ignore" $argv[1] \
37-
(test -r "$FZF_DEFAULT_OPTS_FILE"; and string join -- ' ' <$FZF_DEFAULT_OPTS_FILE) \
38-
$FZF_DEFAULT_OPTS $argv[2..-1]
39-
end
40-
4129
function __fzf_comprun
4230
# $argv[1]: command word (for custom _fzf_comprun function)
4331
# $argv[2..]: fzf arguments
4432
if type -q _fzf_comprun
4533
_fzf_comprun $argv
46-
else if test -n "$TMUX_PANE"; and begin
47-
test -n "$FZF_TMUX" -a "$FZF_TMUX" != 0; or test -n "$FZF_TMUX_OPTS"
48-
end
49-
set -l tmux_opts
50-
if test -n "$FZF_TMUX_OPTS"
51-
set tmux_opts $FZF_TMUX_OPTS
52-
else
53-
set tmux_opts -d$FZF_TMUX_HEIGHT
54-
end
55-
eval fzf-tmux $tmux_opts -- $argv[2..-1]
5634
else
5735
fzf $argv[2..-1]
5836
end
@@ -113,7 +91,7 @@ function fzf_completion_setup
11391
end
11492

11593
# Run fzf
116-
set -lx FZF_DEFAULT_OPTS (__fzf_completion_defaults "--reverse --scheme=path" "$FZF_COMPLETION_OPTS")
94+
set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --scheme=path" "$FZF_COMPLETION_OPTS")
11795
set -lx FZF_DEFAULT_COMMAND
11896
set -lx FZF_DEFAULT_OPTS_FILE
11997

@@ -209,36 +187,29 @@ function fzf_completion_setup
209187
# Get the command word
210188
set -l cmd_word $tokens[1]
211189

212-
# Extract the current token
213-
set -l current_token ""
214-
set -l token_start 1
215-
set -l lbuf_len (string length -- "$lbuf")
216-
for i in (seq $lbuf_len -1 1)
217-
set -l char (string sub -s $i -l 1 -- "$lbuf")
218-
if test "$char" = ' ' -o "$char" = \t
219-
set token_start (math $i + 1)
220-
break
221-
end
222-
end
223-
set current_token (string sub -s $token_start -- "$lbuf")
190+
# Get current token in two forms:
191+
# - raw_token: preserves quotes/escapes, for lbuf calculation
192+
# - current_token: processed by shell, for prefix calculation
193+
set -l raw_token (commandline --current-token 2>/dev/null | string collect)
194+
set -l current_token (commandline --current-token --tokenize 2>/dev/null | string collect)
224195

225-
# Calculate prefix
196+
# Calculate prefix by removing trigger from current token (processed)
226197
set -l prefix
227198
if test -z "$trigger"
228199
set prefix "$current_token"
229200
else
230-
set -l trigger_len (string length -- "$trigger")
231-
set -l token_len (string length -- "$current_token")
232-
set -l prefix_len (math $token_len - $trigger_len)
201+
set -l prefix_len (math (string length -- "$current_token") - (string length -- "$trigger"))
233202
if test $prefix_len -gt 0
234203
set prefix (string sub -l $prefix_len -- "$current_token")
235204
else
236205
set prefix ""
237206
end
238207
end
239208

240-
# Calculate lbuf without current token
241-
set -l new_len (math $token_start - 1)
209+
# Calculate lbuf without current token (use raw_token to match command line)
210+
set -l token_len (string length -- "$raw_token")
211+
set -l lbuf_len (string length -- "$lbuf")
212+
set -l new_len (math $lbuf_len - $token_len)
242213
if test $new_len -gt 0
243214
set lbuf (string sub -l $new_len -- "$lbuf")
244215
else

0 commit comments

Comments
 (0)