diff --git a/book/src/generated/static-cmd.md b/book/src/generated/static-cmd.md index 08c8e7023a7f..a4ebf3707f7c 100644 --- a/book/src/generated/static-cmd.md +++ b/book/src/generated/static-cmd.md @@ -280,6 +280,7 @@ | `dap_disable_exceptions` | Disable exception breakpoints | normal: `` GE ``, select: `` GE `` | | `shell_pipe` | Pipe selections through shell command | normal: `` \| ``, select: `` \| `` | | `shell_pipe_to` | Pipe selections into shell command ignoring output | normal: `` ``, select: `` `` | +| `shell_pipe_all` | Pipe entire document into shell command ignoring output. | | | `shell_insert_output` | Insert shell command output before selections | normal: `` ! ``, select: `` ! `` | | `shell_append_output` | Append shell command output after selections | normal: `` ``, select: `` `` | | `shell_keep_pipe` | Filter selections with shell predicate | normal: `` $ ``, select: `` $ `` | diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index f0d9a0f492a5..dc88cf04dec6 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -81,6 +81,7 @@ | `: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. | +| `:pipe-all` | Pipe entire document to the shell command, ignoring output. | | `:run-shell-command`, `:sh` | Run a shell command | | `:reset-diff-change`, `:diffget`, `:diffg` | Reset the diff change at the cursor position. | | `:clear-register` | Clear given register. If no argument is provided, clear all registers. | diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 0bfb12ad2e9a..626974079a79 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -573,6 +573,7 @@ impl MappableCommand { dap_disable_exceptions, "Disable exception breakpoints", shell_pipe, "Pipe selections through shell command", shell_pipe_to, "Pipe selections into shell command ignoring output", + shell_pipe_all, "Pipe entire document into shell command ignoring output.", shell_insert_output, "Insert shell command output before selections", shell_append_output, "Append shell command output after selections", shell_keep_pipe, "Filter selections with shell predicate", @@ -5859,6 +5860,10 @@ fn shell_pipe_to(cx: &mut Context) { shell_prompt(cx, "pipe-to:".into(), ShellBehavior::Ignore); } +fn shell_pipe_all(cx: &mut Context) { + shell_prompt(cx, "pipe-all:".into(), ShellBehavior::Ignore); +} + fn shell_insert_output(cx: &mut Context) { shell_prompt(cx, "insert-output:".into(), ShellBehavior::Insert); } diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index c21743d0823a..58645fcb4fca 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2290,6 +2290,28 @@ fn pipe_impl( Ok(()) } +fn pipe_all( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + + ensure!(!args.is_empty(), "Shell command required"); + let cmd = args.join(" "); + + let shell = &cx.editor.config().shell; + let text = current!(cx.editor).1.text().slice(..); + + if let Err(err) = shell_impl(shell, &cmd, Some(text.into())) { + cx.editor.set_error(err.to_string()); + } + + Ok(()) +} + fn run_shell_command( cx: &mut compositor::Context, args: &[Cow], @@ -3101,6 +3123,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: pipe_to, signature: CommandSignature::none(), }, + TypableCommand { + name: "pipe-all", + aliases: &[], + doc: "Pipe entire document to the shell command, ignoring output.", + fun: pipe_all, + signature: CommandSignature::none(), + }, TypableCommand { name: "run-shell-command", aliases: &["sh"],