From 96c3de12eb717e33b175fd01a9aaaac84ea8d6af Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 12 Feb 2023 22:06:21 +0900 Subject: [PATCH] Run 'become' only when the command template is properly evaluated --- src/terminal.go | 26 ++++++++++++++------------ test/test_go.rb | 12 +++++++++--- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index 13968a39..18f83530 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -2863,19 +2863,21 @@ func (t *Terminal) Loop() { switch a.t { case actIgnore: case actBecome: - _, list := t.buildPlusList(a.a, false) - command := t.replacePlaceholder(a.a, false, string(t.input), list) - shell := os.Getenv("SHELL") - if len(shell) == 0 { - shell = "sh" - } - shellPath, err := exec.LookPath(shell) - if err == nil { - t.tui.Close() - if t.history != nil { - t.history.append(string(t.input)) + valid, list := t.buildPlusList(a.a, false) + if valid { + command := t.replacePlaceholder(a.a, false, string(t.input), list) + shell := os.Getenv("SHELL") + if len(shell) == 0 { + shell = "sh" + } + shellPath, err := exec.LookPath(shell) + if err == nil { + t.tui.Close() + if t.history != nil { + t.history.append(string(t.input)) + } + syscall.Exec(shellPath, []string{shell, "-c", command}, os.Environ()) } - syscall.Exec(shellPath, []string{shell, "-c", command}, os.Environ()) } case actExecute, actExecuteSilent: t.executeCommand(a.a, false, a.t == actExecuteSilent, false) diff --git a/test/test_go.rb b/test/test_go.rb index bcc18dc4..6ef2d62c 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -2645,10 +2645,16 @@ class TestGoFZF < TestBase end def test_become - tmux.send_keys "seq 10 | #{FZF} --bind 'enter:become:seq 100 | #{FZF}'", :Enter - tmux.until { |lines| assert_equal 10, lines.item_count } - tmux.send_keys :Enter + tmux.send_keys "seq 100 | #{FZF} --bind 'enter:become:seq {} | #{FZF}'", :Enter tmux.until { |lines| assert_equal 100, lines.item_count } + tmux.send_keys 999 + tmux.until { |lines| assert_equal 0, lines.match_count } + tmux.send_keys :Enter + tmux.until { |lines| assert_equal 0, lines.match_count } + tmux.send_keys :BSpace + tmux.until { |lines| assert_equal 1, lines.match_count } + tmux.send_keys :Enter + tmux.until { |lines| assert_equal 99, lines.item_count } end end