Skip to content

Commit 01444e8

Browse files
alxshineFrederik Vestre
authored and
Frederik Vestre
committed
Add :pipe-to typable command that ignores shell output (helix-editor#4931)
1 parent 92c2e4d commit 01444e8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

book/src/generated/typable-cmd.md

+1
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@
7171
| `:insert-output` | Run shell command, inserting output before each selection. |
7272
| `:append-output` | Run shell command, appending output after each selection. |
7373
| `:pipe` | Pipe each selection to the shell command. |
74+
| `:pipe-to` | Pipe each selection to the shell command, ignoring output. |
7475
| `:run-shell-command`, `:sh` | Run a shell command |

helix-term/src/commands/typed.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -1741,13 +1741,30 @@ fn insert_output(
17411741
Ok(())
17421742
}
17431743

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+
17441752
fn 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<()> {
17451762
if event != PromptEvent::Validate {
17461763
return Ok(());
17471764
}
17481765

17491766
ensure!(!args.is_empty(), "Shell command required");
1750-
shell(cx, &args.join(" "), &ShellBehavior::Replace);
1767+
shell(cx, &args.join(" "), behavior);
17511768
Ok(())
17521769
}
17531770

@@ -2292,6 +2309,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
22922309
fun: pipe,
22932310
completer: None,
22942311
},
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+
},
22952319
TypableCommand {
22962320
name: "run-shell-command",
22972321
aliases: &["sh"],

0 commit comments

Comments
 (0)