Merge pull request #620 from crinklywrappr/add-elvish-widget

Add elvish widget
This commit is contained in:
Denis Isidoro 2021-09-10 15:57:20 -03:00 committed by GitHub
commit ec35cd0edc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 1 deletions

View file

@ -85,6 +85,9 @@ eval "$(navi widget zsh)"
# fish
navi widget fish | source
# elvish
eval (navi widget elvish | slurp)
```
By default, `Ctrl+G` is assigned to launching **navi**.

31
shell/navi.plugin.elv Normal file
View file

@ -0,0 +1,31 @@
use str
fn call-navi []{
if (eq $edit:current-command '') {
answer = (navi --print)
edit:replace-input $answer
} elif (not (str:contains-any $edit:current-command '|')) {
answer = (navi --print --query $edit:current-command)
if (not-eq $answer '') {
edit:replace-input $answer
}
} else {
cmds = [(str:split '|' $edit:current-command)]
qty = (- (count $cmds) 1)
query = (all $cmds | drop $qty)
cmds = [(all $cmds | take $qty)]
answer = ''
if (eq $query '') {
answer = (navi --print)
} else {
answer = (navi --print --query $query)
}
if (not-eq $answer '') {
cmds = [$@cmds $answer]
edit:replace-input (str:join '| ' $cmds)
}
}
}
edit:insert:binding[Alt-h] = []{ call-navi >/dev/tty 2>&1 }

View file

@ -9,7 +9,7 @@ use clap::{crate_version, AppSettings, Clap};
use std::str::FromStr;
const FINDER_POSSIBLE_VALUES: &[&str] = &["fzf", "skim"];
const WIDGET_POSSIBLE_VALUES: &[&str] = &["bash", "zsh", "fish"];
const WIDGET_POSSIBLE_VALUES: &[&str] = &["bash", "zsh", "fish", "elvish"];
const FUNC_POSSIBLE_VALUES: &[&str] = &["url::open", "welcome", "widget::last_command", "map::expand"];
const INFO_POSSIBLE_VALUES: &[&str] = &["cheats-example", "cheats-path", "config-path", "config-example"];
@ -21,6 +21,7 @@ impl FromStr for Shell {
"bash" => Ok(Shell::Bash),
"zsh" => Ok(Shell::Zsh),
"fish" => Ok(Shell::Fish),
"elvish" => Ok(Shell::Elvish),
_ => Err("no match"),
}
}

View file

@ -6,6 +6,7 @@ pub fn main(shell: &Shell) -> Result<()> {
Shell::Bash => include_str!("../../shell/navi.plugin.bash"),
Shell::Zsh => include_str!("../../shell/navi.plugin.zsh"),
Shell::Fish => include_str!("../../shell/navi.plugin.fish"),
Shell::Elvish => include_str!("../../shell/navi.plugin.elv"),
};
println!("{}", content);

View file

@ -12,6 +12,7 @@ pub enum Shell {
Bash,
Zsh,
Fish,
Elvish,
}
#[derive(Error, Debug)]

View file

@ -158,6 +158,7 @@ test::set_suite "widget"
test::run "bash" _navi_widget "bash"
test::run "zsh" _navi_widget "zsh"
test::run "zsh" _navi_widget "fish"
test::run "elvish" _navi_widget "elvish"
test::set_suite "3rd party"
test::run "tldr" _navi_tldr