Skip to content

Commit 02e692c

Browse files
committed
fix(init): handle Fish empty-line collapse in fzf --expect output
Fish command substitution collapses empty lines, so when Enter is pressed with --expect, the empty key line disappears and the array has only 1 element instead of 2. Detect this by checking count and adjust indices accordingly. Also strengthen the fish enter test to validate string split + set dir parsing rather than just checking for 'cd '.
1 parent bb0a3a2 commit 02e692c

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/commands/init.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,15 @@ function __FUNC__
341341
or return 0
342342
test -z "$_gtr_selection"; and return 0
343343
# --expect gives two lines: key (index 1) and selection (index 2)
344-
set -l _gtr_key "$_gtr_selection[1]"
345-
set -l _gtr_line "$_gtr_selection[2]"
344+
# Fish collapses empty lines in command substitution, so when Enter
345+
# is pressed the empty key line disappears and count drops to 1.
346+
if test (count $_gtr_selection) -eq 1
347+
set -l _gtr_key ""
348+
set -l _gtr_line "$_gtr_selection[1]"
349+
else
350+
set -l _gtr_key "$_gtr_selection[1]"
351+
set -l _gtr_line "$_gtr_selection[2]"
352+
end
346353
test -z "$_gtr_line"; and return 0
347354
# ctrl-a/ctrl-e: run after fzf exits (needs full terminal for TUI apps)
348355
if test "$_gtr_key" = "ctrl-a"

tests/init.bats

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ setup() {
241241
@test "fish fzf enter extracts path from selection and cd" {
242242
run cmd_init fish
243243
[ "$status" -eq 0 ]
244-
# Fish uses string split or cut to extract path
245-
[[ "$output" == *'cd '* ]]
244+
# Fish uses string split to extract path, then cd
245+
[[ "$output" == *'string split'* ]]
246+
[[ "$output" == *'set dir'* ]]
247+
[[ "$output" == *'cd $dir'* ]]
246248
}
247249
248250
# ── fzf: ctrl-e (editor) — via --expect ──────────────────────────────────────

0 commit comments

Comments
 (0)