Skip to content

Commit 9b5e430

Browse files
author
sarah
committed
add async shell command
1 parent 7704965 commit 9b5e430

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

book/src/generated/typable-cmd.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@
7676
| `:pipe` | Pipe each selection to the shell command. |
7777
| `:pipe-to` | Pipe each selection to the shell command, ignoring output. |
7878
| `:run-shell-command`, `:sh` | Run a shell command |
79+
| `:run-async-shell-command`, `:async-sh` | Run a shell command asynchronously |
7980
| `:reset-diff-change`, `:diffget`, `:diffg` | Reset the diff change at the cursor position. |

helix-term/src/commands.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5037,6 +5037,13 @@ fn shell_impl(shell: &[String], cmd: &str, input: Option<Rope>) -> anyhow::Resul
50375037
tokio::task::block_in_place(|| helix_lsp::block_on(shell_impl_async(shell, cmd, input)))
50385038
}
50395039

5040+
fn async_shell_impl(shell: &[String], cmd: &str, input: Option<Rope>) -> anyhow::Result<()> {
5041+
let shell = shell.to_vec();
5042+
let cmd = cmd.to_string();
5043+
tokio::task::spawn(async move { shell_impl_async(&shell, &cmd, input).await.map(|_| ()) });
5044+
Ok(())
5045+
}
5046+
50405047
async fn shell_impl_async(
50415048
shell: &[String],
50425049
cmd: &str,

helix-term/src/commands/typed.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,19 @@ fn run_shell_command(
20912091
Ok(())
20922092
}
20932093

2094+
fn run_async_shell_command(
2095+
cx: &mut compositor::Context,
2096+
args: &[Cow<str>],
2097+
event: PromptEvent,
2098+
) -> anyhow::Result<()> {
2099+
if event != PromptEvent::Validate {
2100+
return Ok(());
2101+
}
2102+
2103+
let shell = &cx.editor.config().shell;
2104+
async_shell_impl(shell, &args.join(" "), None)
2105+
}
2106+
20942107
fn reset_diff_change(
20952108
cx: &mut compositor::Context,
20962109
args: &[Cow<str>],
@@ -2688,7 +2701,14 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
26882701
fun: run_shell_command,
26892702
signature: CommandSignature::all(completers::filename)
26902703
},
2691-
TypableCommand {
2704+
TypableCommand {
2705+
name: "run-async-shell-command",
2706+
aliases: &["async-sh"],
2707+
doc: "Run a shell command asynchronously",
2708+
fun: run_async_shell_command,
2709+
signature: CommandSignature::all(completers::filename)
2710+
},
2711+
TypableCommand {
26922712
name: "reset-diff-change",
26932713
aliases: &["diffget", "diffg"],
26942714
doc: "Reset the diff change at the cursor position.",

0 commit comments

Comments
 (0)