Skip to content

Commit

Permalink
Merge pull request #901 from suimong/master
Browse files Browse the repository at this point in the history
add integration with nushell
  • Loading branch information
denisidoro authored Jun 30, 2024
2 parents 52e90ad + afc4883 commit 0a1413f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ eval (navi widget elvish | slurp)
xontrib load navi # ← add to your xonsh run control file
```
#### Nushell
Due to Nushell's [unique design](https://www.nushell.sh/book/thinking_in_nu.html#think-of-nushell-as-a-compiled-language), it is not possible to `eval` a piece of code dynamically like in other shells therefore the integration process is a bit more involved. Here is an example:
1. run `^navi widget nushell | save ($nu.default-config-dir | path join "navi-integration.nu")`
2. add the following lines to `config.nu`:
```nushell
source ($nu.default-config-dir | path join "navi-integration.nu")
```


By default, `Ctrl+G` is assigned to launching **navi** (in xonsh can be customized with `$X_NAVI_KEY`, see [xontrib-navi](https://github.com/eugenesvk/xontrib-navi) for details).

There's currently no way to customize the widget behavior out-of-the-box. If you want to change the keybinding or the **navi** flags used by the widget, please:
Expand Down
34 changes: 34 additions & 0 deletions shell/navi.plugin.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export def navi_widget [] {
let current_input = (commandline)
let last_command = ($current_input | navi fn widget::last_command | str trim)

match ($last_command | is-empty) {
true => {^navi --print | complete | get "stdout"}
false => {
let find = $"($last_command)_NAVIEND"
let replacement = (^navi --print --query $'($last_command)' | complete | get "stdout")

match ($replacement | str trim | is-empty) {
false => {$"($current_input)_NAVIEND" | str replace $find $replacement}
true => $current_input
}
}
}
| str trim
| commandline edit --replace $in

commandline set-cursor --end
}

let nav_keybinding = {
name: "navi",
modifier: control,
keycode: char_g,
mode: [emacs, vi_normal, vi_insert],
event: {
send: executehostcommand,
cmd: navi_widget,
}
}

$env.config.keybindings = ($env.config.keybindings | append $nav_keybinding)
2 changes: 2 additions & 0 deletions src/commands/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl Display for Shell {
Self::Zsh => "zsh",
Self::Fish => "fish",
Self::Elvish => "elvish",
Self::Nushell => "nushell",
};

write!(f, "{s}")
Expand All @@ -34,6 +35,7 @@ impl Runnable for Input {
Shell::Zsh => include_str!("../../shell/navi.plugin.zsh"),
Shell::Fish => include_str!("../../shell/navi.plugin.fish"),
Shell::Elvish => include_str!("../../shell/navi.plugin.elv"),
Shell::Nushell => include_str!("../../shell/navi.plugin.nu"),
};

println!("{content}");
Expand Down
1 change: 1 addition & 0 deletions src/common/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum Shell {
Zsh,
Fish,
Elvish,
Nushell
}

#[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 @@ -159,6 +159,7 @@ test::run "bash" _navi_widget "bash"
test::run "zsh" _navi_widget "zsh"
test::run "fish" _navi_widget "fish"
test::run "elvish" _navi_widget "elvish"
test::run "nu" _navi_widget "nushell"

test::set_suite "3rd party"
test::run "tldr" _navi_tldr
Expand Down

0 comments on commit 0a1413f

Please sign in to comment.