Skip to content

Commit

Permalink
Add elvish widget
Browse files Browse the repository at this point in the history
  • Loading branch information
crinklywrappr committed Sep 8, 2021
1 parent 86b5bef commit 715d3d5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down
31 changes: 31 additions & 0 deletions shell/navi.plugin.elv
Original file line number Diff line number Diff line change
@@ -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 }
3 changes: 2 additions & 1 deletion src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand All @@ -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"),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/handler/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum Shell {
Bash,
Zsh,
Fish,
Elvish,
}

#[derive(Error, Debug)]
Expand Down
1 change: 1 addition & 0 deletions tests/run
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 715d3d5

Please sign in to comment.