Run 'become' only when the command template is properly evaluated

pull/3163/head
Junegunn Choi 1 year ago
parent 719dbb8bae
commit 96c3de12eb
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -2863,19 +2863,21 @@ func (t *Terminal) Loop() {
switch a.t { switch a.t {
case actIgnore: case actIgnore:
case actBecome: case actBecome:
_, list := t.buildPlusList(a.a, false) valid, list := t.buildPlusList(a.a, false)
command := t.replacePlaceholder(a.a, false, string(t.input), list) if valid {
shell := os.Getenv("SHELL") command := t.replacePlaceholder(a.a, false, string(t.input), list)
if len(shell) == 0 { shell := os.Getenv("SHELL")
shell = "sh" if len(shell) == 0 {
} shell = "sh"
shellPath, err := exec.LookPath(shell) }
if err == nil { shellPath, err := exec.LookPath(shell)
t.tui.Close() if err == nil {
if t.history != nil { t.tui.Close()
t.history.append(string(t.input)) 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: case actExecute, actExecuteSilent:
t.executeCommand(a.a, false, a.t == actExecuteSilent, false) t.executeCommand(a.a, false, a.t == actExecuteSilent, false)

@ -2645,10 +2645,16 @@ class TestGoFZF < TestBase
end end
def test_become def test_become
tmux.send_keys "seq 10 | #{FZF} --bind 'enter:become:seq 100 | #{FZF}'", :Enter tmux.send_keys "seq 100 | #{FZF} --bind 'enter:become:seq {} | #{FZF}'", :Enter
tmux.until { |lines| assert_equal 10, lines.item_count }
tmux.send_keys :Enter
tmux.until { |lines| assert_equal 100, lines.item_count } 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
end end

Loading…
Cancel
Save