on master help sign in
Add shell insert commands to typable and config (#2589)

* Add shell insert commands to typable and config * generate docs Co-authored-by: Dean Revell <revell@gmail.com>

commitf1ae496860e10560d9a8b91a721168524411096a authorTermina94 <47091253+Termina94@users.noreply.github.com> dateSun 5 Jun 2022, 11:52 (4 years ago) parentf92a25a
2 files changed+36
book/src/generated/typable-cmd.md+2 helix-term/src/commands/typed.rs+34
book/src/generated/typable-cmd.md+2
@@ -64,5 +64,7 @@
6464| `:config-reload` | Refreshes helix's config. |
6565| `:config-open` | Open the helix config.toml file. |
6666| `:log-open` | Open the helix log file. |
67+| `:insert-output` | Run shell command, inserting output after each selection. |
68+| `:append-output` | Run shell command, appending output after each selection. |
6769| `:pipe` | Pipe each selection to the shell command. |
6870| `:run-shell-command`, `:sh` | Run a shell command |
helix-term/src/commands/typed.rs+34
@@ -1172,6 +1172,26 @@ fn refresh_config(
11721172 Ok(())
11731173}
11741174
1175+fn append_output(
1176+ cx: &mut compositor::Context,
1177+ args: &[Cow<str>],
1178+ _event: PromptEvent,
1179+) -> anyhow::Result<()> {
1180+ ensure!(!args.is_empty(), "Shell command required");
1181+ shell(cx, &args.join(" "), &ShellBehavior::Append);
1182+ Ok(())
1183+}
1184+
1185+fn insert_output(
1186+ cx: &mut compositor::Context,
1187+ args: &[Cow<str>],
1188+ _event: PromptEvent,
1189+) -> anyhow::Result<()> {
1190+ ensure!(!args.is_empty(), "Shell command required");
1191+ shell(cx, &args.join(" "), &ShellBehavior::Insert);
1192+ Ok(())
1193+}
1194+
11751195fn pipe(
11761196 cx: &mut compositor::Context,
11771197 args: &[Cow<str>],
@@ -1671,6 +1691,20 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
16711691 fun: open_log,
16721692 completer: None,
16731693 },
1694+ TypableCommand {
1695+ name: "insert-output",
1696+ aliases: &[],
1697+ doc: "Run shell command, inserting output after each selection.",
1698+ fun: insert_output,
1699+ completer: None,
1700+ },
1701+ TypableCommand {
1702+ name: "append-output",
1703+ aliases: &[],
1704+ doc: "Run shell command, appending output after each selection.",
1705+ fun: append_output,
1706+ completer: None,
1707+ },
16741708 TypableCommand {
16751709 name: "pipe",
16761710 aliases: &[],