From f1ae496860e10560d9a8b91a721168524411096a Mon Sep 17 00:00:00 2001 From: Termina94 <47091253+Termina94@users.noreply.github.com> Date: Sun, 5 Jun 2022 11:52:41 +0100 Subject: [PATCH] Add shell insert commands to typable and config (#2589) * Add shell insert commands to typable and config * generate docs Co-authored-by: Dean Revell --- book/src/generated/typable-cmd.md | 2 ++ helix-term/src/commands/typed.rs | 34 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 5ae184daf..71a33fa72 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -64,5 +64,7 @@ | `:config-reload` | Refreshes helix's config. | | `:config-open` | Open the helix config.toml file. | | `:log-open` | Open the helix log file. | +| `:insert-output` | Run shell command, inserting output after each selection. | +| `: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 | diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index fd33e6b4c..0f8884dbb 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1172,6 +1172,26 @@ fn refresh_config( Ok(()) } +fn append_output( + cx: &mut compositor::Context, + args: &[Cow], + _event: PromptEvent, +) -> anyhow::Result<()> { + ensure!(!args.is_empty(), "Shell command required"); + shell(cx, &args.join(" "), &ShellBehavior::Append); + Ok(()) +} + +fn insert_output( + cx: &mut compositor::Context, + args: &[Cow], + _event: PromptEvent, +) -> anyhow::Result<()> { + ensure!(!args.is_empty(), "Shell command required"); + shell(cx, &args.join(" "), &ShellBehavior::Insert); + Ok(()) +} + fn pipe( cx: &mut compositor::Context, args: &[Cow], @@ -1671,6 +1691,20 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: open_log, completer: None, }, + TypableCommand { + name: "insert-output", + aliases: &[], + doc: "Run shell command, inserting output after each selection.", + fun: insert_output, + completer: None, + }, + TypableCommand { + name: "append-output", + aliases: &[], + doc: "Run shell command, appending output after each selection.", + fun: append_output, + completer: None, + }, TypableCommand { name: "pipe", aliases: &[],