From 79a76e38f43b615998559821bc34b8570968fd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Schl=C3=B6gl?= Date: Tue, 29 Nov 2022 12:22:52 +0100 Subject: [PATCH 1/3] Add pipe-to TypableCommand that ignores output --- helix-term/src/commands/typed.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 351692fd24df..96480c07aa02 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1734,13 +1734,30 @@ fn insert_output( Ok(()) } +fn pipe_to( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + _pipe(cx, args, event, &ShellBehavior::Ignore) +} + fn pipe(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { + _pipe(cx, args, event, &ShellBehavior::Replace) +} + +fn _pipe( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, + behavior: &ShellBehavior, +) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } ensure!(!args.is_empty(), "Shell command required"); - shell(cx, &args.join(" "), &ShellBehavior::Replace); + shell(cx, &args.join(" "), behavior); Ok(()) } @@ -2285,6 +2302,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: pipe, completer: None, }, + TypableCommand { + name: "pipe-to", + aliases: &[], + doc: "Pipe each selection to the shell command, ignoring output.", + fun: pipe_to, + completer: None, + }, TypableCommand { name: "run-shell-command", aliases: &["sh"], From 89c13e66aef4afe9a90ba8705b25c4e95daf8b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Schl=C3=B6gl?= Date: Tue, 29 Nov 2022 12:31:08 +0100 Subject: [PATCH 2/3] Re-generate book --- book/src/generated/typable-cmd.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 6390ef858e7b..66e6ac039c26 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -71,4 +71,5 @@ | `:insert-output` | Run shell command, inserting output before each selection. | | `:append-output` | Run shell command, appending output after each selection. | | `:pipe` | Pipe each selection to the shell command. | +| `:pipe-to` | Pipe each selection to the shell command, ignoring output. | | `:run-shell-command`, `:sh` | Run a shell command | From c49829fcd9ce650b066fe8e467a0916eef35a3fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Schl=C3=B6gl?= Date: Tue, 29 Nov 2022 15:42:57 +0100 Subject: [PATCH 3/3] Rename _pipe to pipe_impl --- helix-term/src/commands/typed.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 96480c07aa02..e5ab9e62c9f0 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1739,14 +1739,14 @@ fn pipe_to( args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { - _pipe(cx, args, event, &ShellBehavior::Ignore) + pipe_impl(cx, args, event, &ShellBehavior::Ignore) } fn pipe(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { - _pipe(cx, args, event, &ShellBehavior::Replace) + pipe_impl(cx, args, event, &ShellBehavior::Replace) } -fn _pipe( +fn pipe_impl( cx: &mut compositor::Context, args: &[Cow], event: PromptEvent,