on master help sign in
Add `:pipe-to` typable command that ignores shell output (#4931)
0b96021Alexander Schlögl
book/src/generated/typable-cmd.md+1
@@ -71,4 +71,5 @@
71| `:insert-output` | Run shell command, inserting output before each selection. |
71| `:insert-output` | Run shell command, inserting output before each selection. |
72| `:append-output` | Run shell command, appending output after each selection. |
72| `:append-output` | Run shell command, appending output after each selection. |
73| `:pipe` | Pipe each selection to the shell command. |
73| `:pipe` | Pipe each selection to the shell command. |
74+| `:pipe-to` | Pipe each selection to the shell command, ignoring output. |
74| `:run-shell-command`, `:sh` | Run a shell command |
75| `:run-shell-command`, `:sh` | Run a shell command |
helix-term/src/commands/typed.rs+25−1
@@ -1741,13 +1741,30 @@ fn insert_output(
1741 Ok(())
1741 Ok(())
1742}
1742}
1743
1743
1744+fn pipe_to(
1745+ cx: &mut compositor::Context,
1746+ args: &[Cow<str>],
1747+ event: PromptEvent,
1748+) -> anyhow::Result<()> {
1749+ pipe_impl(cx, args, event, &ShellBehavior::Ignore)
1750+}
1751+
1744fn pipe(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) -> anyhow::Result<()> {
1752fn pipe(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) -> anyhow::Result<()> {
1753+ pipe_impl(cx, args, event, &ShellBehavior::Replace)
1754+}
1755+
1756+fn pipe_impl(
1757+ cx: &mut compositor::Context,
1758+ args: &[Cow<str>],
1759+ event: PromptEvent,
1760+ behavior: &ShellBehavior,
1761+) -> anyhow::Result<()> {
1745 if event != PromptEvent::Validate {
1762 if event != PromptEvent::Validate {
1746 return Ok(());
1763 return Ok(());
1747 }
1764 }
1748
1765
1749 ensure!(!args.is_empty(), "Shell command required");
1766 ensure!(!args.is_empty(), "Shell command required");
1750− shell(cx, &args.join(" "), &ShellBehavior::Replace);
1767+ shell(cx, &args.join(" "), behavior);
1751 Ok(())
1768 Ok(())
1752}
1769}
1753
1770
@@ -2292,6 +2309,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2292 fun: pipe,
2309 fun: pipe,
2293 completer: None,
2310 completer: None,
2294 },
2311 },
2312+ TypableCommand {
2313+ name: "pipe-to",
2314+ aliases: &[],
2315+ doc: "Pipe each selection to the shell command, ignoring output.",
2316+ fun: pipe_to,
2317+ completer: None,
2318+ },
2295 TypableCommand {
2319 TypableCommand {
2296 name: "run-shell-command",
2320 name: "run-shell-command",
2297 aliases: &["sh"],
2321 aliases: &["sh"],