Skip to content

Commit d182c32

Browse files
authored
fix(init): keep fish fzf selection in scope (#172)
1 parent b8ca496 commit d182c32

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

lib/commands/init.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,14 @@ function __FUNC__
509509
# --expect gives two lines: key (index 1) and selection (index 2)
510510
# Fish collapses empty lines in command substitution, so when Enter
511511
# is pressed the empty key line disappears and count drops to 1.
512+
set -l _gtr_key
513+
set -l _gtr_line
512514
if test (count $_gtr_selection) -eq 1
513-
set -l _gtr_key ""
514-
set -l _gtr_line "$_gtr_selection[1]"
515+
set _gtr_key ""
516+
set _gtr_line "$_gtr_selection[1]"
515517
else
516-
set -l _gtr_key "$_gtr_selection[1]"
517-
set -l _gtr_line "$_gtr_selection[2]"
518+
set _gtr_key "$_gtr_selection[1]"
519+
set _gtr_line "$_gtr_selection[2]"
518520
end
519521
if test "$_gtr_key" = "ctrl-n"
520522
read -P "Branch name: " _gtr_branch

tests/init.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,17 @@ require_runtime_shell() {
476476
[[ "$output" == *'cd $dir'* ]]
477477
}
478478
479+
@test "fish fzf enter keeps selection variables in function scope" {
480+
run cmd_init fish
481+
[ "$status" -eq 0 ]
482+
[[ "$output" == *'set -l _gtr_key'* ]]
483+
[[ "$output" == *'set -l _gtr_line'* ]]
484+
[[ "$output" == *'set _gtr_key ""'* ]]
485+
[[ "$output" == *'set _gtr_line "$_gtr_selection[1]"'* ]]
486+
[[ "$output" != *'set -l _gtr_key ""'* ]]
487+
[[ "$output" != *'set -l _gtr_line "$_gtr_selection[1]"'* ]]
488+
}
489+
479490
# ── fzf: ctrl-e (editor) — via --expect ──────────────────────────────────────
480491
481492
@test "bash fzf ctrl-e handled via --expect for full terminal access" {

0 commit comments

Comments
 (0)