Skip to content

Commit

Permalink
Add :pipe-to typable command that ignores shell output (helix-edito…
Browse files Browse the repository at this point in the history
  • Loading branch information
alxshine authored and Frederik Vestre committed Feb 6, 2023
1 parent 92c2e4d commit 01444e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions book/src/generated/typable-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
26 changes: 25 additions & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,13 +1741,30 @@ fn insert_output(
Ok(())
}

fn pipe_to(
cx: &mut compositor::Context,
args: &[Cow<str>],
event: PromptEvent,
) -> anyhow::Result<()> {
pipe_impl(cx, args, event, &ShellBehavior::Ignore)
}

fn pipe(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) -> anyhow::Result<()> {
pipe_impl(cx, args, event, &ShellBehavior::Replace)
}

fn pipe_impl(
cx: &mut compositor::Context,
args: &[Cow<str>],
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(())
}

Expand Down Expand Up @@ -2292,6 +2309,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"],
Expand Down

0 comments on commit 01444e8

Please sign in to comment.