diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 653acf60cac1f..9fc28a78bf500 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -68,3 +68,4 @@ | `:append-output` | Run shell command, appending output after each selection. | | `:pipe` | Pipe each selection to the shell command. | | `:run-shell-command`, `:sh` | Run a shell command | +| `:run-shell-command-no-output`, `:sh!` | Run a shell command ignoring output | diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index f6eedea9567aa..496d80fa2af0a 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1475,10 +1475,27 @@ fn pipe(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> Ok(()) } +fn run_shell_command_no_output( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + run_shell_command_impl(cx, args, event, ShellBehavior::Ignore) +} + fn run_shell_command( cx: &mut compositor::Context, args: &[Cow], event: PromptEvent, +) -> anyhow::Result<()> { + run_shell_command_impl(cx, args, event, ShellBehavior::Append) +} + +fn run_shell_command_impl( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, + behavior: ShellBehavior ) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); @@ -1492,7 +1509,7 @@ fn run_shell_command( cx.editor.set_error("Command failed"); } - if !output.is_empty() { + if !output.is_empty() && behavior != ShellBehavior::Ignore { let callback = async move { let call: job::Callback = Box::new(move |editor: &mut Editor, compositor: &mut Compositor| { @@ -1994,6 +2011,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: run_shell_command, completer: Some(completers::directory), }, + TypableCommand { + name: "run-shell-command-no-output", + aliases: &["sh!"], + doc: "Run a shell command ignoring output", + fun: run_shell_command_no_output, + completer: Some(completers::directory) + } ]; pub static TYPABLE_COMMAND_MAP: Lazy> =