diff --git a/skim/src/bin/main.rs b/skim/src/bin/main.rs index 3e715aec..c89cf7c2 100644 --- a/skim/src/bin/main.rs +++ b/skim/src/bin/main.rs @@ -129,16 +129,8 @@ fn sk_main() -> Result { print!("{}{}", result.cmd, bin_options.output_ending); } - if !opts.expect.is_empty() { - match result.final_event { - Event::EvActAccept(Some(accept_key)) => { - print!("{}{}", accept_key, bin_options.output_ending); - } - Event::EvActAccept(None) => { - print!("{}", bin_options.output_ending); - } - _ => {} - } + if let Event::EvActAccept(Some(accept_key)) = result.final_event { + print!("{}{}", accept_key, bin_options.output_ending); } for item in result.selected_items.iter() { diff --git a/skim/src/options.rs b/skim/src/options.rs index c5128fef..881abeea 100644 --- a/skim/src/options.rs +++ b/skim/src/options.rs @@ -222,7 +222,7 @@ pub struct SkimOptions { /// /// ACTION: DEFAULT BINDINGS (NOTES): /// abort ctrl-c ctrl-q esc - /// accept enter + /// accept(...) enter (the argument will be printed when the binding is triggered) /// append-and-select /// backward-char ctrl-b left /// backward-delete-char ctrl-h bspace diff --git a/test/run.sh b/test/run.sh index bb5bdb56..eb1e173a 100755 --- a/test/run.sh +++ b/test/run.sh @@ -4,6 +4,7 @@ set -euo pipefail TEST_CLASS=test_skim.TestSkim +cd $(dirname "$0") tests=$(sed -n 's/^\s\+def \(test_\w\+\)(self.*):\s*$/\1/p' test_skim.py | \ sk --multi) diff --git a/test/test_skim.py b/test/test_skim.py index 034dff3e..dcf56e04 100644 --- a/test/test_skim.py +++ b/test/test_skim.py @@ -1375,6 +1375,17 @@ class TestSkim(TestBase): self.tmux.until(lambda l: l.ready_with_matches(2)) self.tmux.until(lambda l: l[-3] == '> a b') + def test_624_accept_no_expect(self): + input_cmd = "echo -e 'a b c\\nd e f'" + args = '--bind ctrl-a:accept:hello' + self.tmux.send_keys(f"{input_cmd} | {self.sk(args)}", Key('Enter')) + self.tmux.until(lambda l: l.ready_with_matches(2)) + self.tmux.send_keys(Ctrl('a')) + out = self.readonce().split('\n') + self.assertEqual(out[-1], '') + self.assertEqual(out[-2], 'a b c') + self.assertEqual(out[-3], 'hello') + def find_prompt(lines, interactive=False, reverse=False): linen = -1 prompt = ">"