Skip to content

Commit

Permalink
Add shell insert commands to typable and config (#2589)
Browse files Browse the repository at this point in the history
* Add shell insert commands to typable and config

* generate docs

Co-authored-by: Dean Revell <revell@gmail.com>
  • Loading branch information
Termina94 and Dean Revell authored Jun 5, 2022
1 parent f92a25a commit f1ae496
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions book/src/generated/typable-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
34 changes: 34 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,26 @@ fn refresh_config(
Ok(())
}

fn append_output(
cx: &mut compositor::Context,
args: &[Cow<str>],
_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<str>],
_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<str>],
Expand Down Expand Up @@ -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: &[],
Expand Down

0 comments on commit f1ae496

Please # to comment.