Skip to content

Commit

Permalink
Adds a run-shell-command-no-output command
Browse files Browse the repository at this point in the history
  • Loading branch information
dariooddenino committed Jul 29, 2022
1 parent a8b123f commit 7d26ea0
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 @@ -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 |
26 changes: 25 additions & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,10 +1475,27 @@ fn pipe(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) ->
Ok(())
}

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

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

fn run_shell_command_impl(
cx: &mut compositor::Context,
args: &[Cow<str>],
event: PromptEvent,
behavior: ShellBehavior
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
Expand All @@ -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| {
Expand Down Expand Up @@ -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<HashMap<&'static str, &'static TypableCommand>> =
Expand Down

0 comments on commit 7d26ea0

Please sign in to comment.