Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/commands/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,14 @@ function __FUNC__
# --expect gives two lines: key (index 1) and selection (index 2)
# Fish collapses empty lines in command substitution, so when Enter
# is pressed the empty key line disappears and count drops to 1.
set -l _gtr_key
set -l _gtr_line
if test (count $_gtr_selection) -eq 1
set -l _gtr_key ""
set -l _gtr_line "$_gtr_selection[1]"
set _gtr_key ""
set _gtr_line "$_gtr_selection[1]"
else
set -l _gtr_key "$_gtr_selection[1]"
set -l _gtr_line "$_gtr_selection[2]"
set _gtr_key "$_gtr_selection[1]"
set _gtr_line "$_gtr_selection[2]"
end
if test "$_gtr_key" = "ctrl-n"
read -P "Branch name: " _gtr_branch
Expand Down
11 changes: 11 additions & 0 deletions tests/init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,17 @@ require_runtime_shell() {
[[ "$output" == *'cd $dir'* ]]
}

@test "fish fzf enter keeps selection variables in function scope" {
run cmd_init fish
[ "$status" -eq 0 ]
[[ "$output" == *'set -l _gtr_key'* ]]
[[ "$output" == *'set -l _gtr_line'* ]]
[[ "$output" == *'set _gtr_key ""'* ]]
[[ "$output" == *'set _gtr_line "$_gtr_selection[1]"'* ]]
[[ "$output" != *'set -l _gtr_key ""'* ]]
[[ "$output" != *'set -l _gtr_line "$_gtr_selection[1]"'* ]]
}

# ── fzf: ctrl-e (editor) — via --expect ──────────────────────────────────────

@test "bash fzf ctrl-e handled via --expect for full terminal access" {
Expand Down
Loading