mirror of
https://github.com/denisidoro/navi
synced 2024-11-24 12:33:05 +00:00
Merge pull request #901 from suimong/master
add integration with nushell
This commit is contained in:
commit
0a1413faa8
5 changed files with 48 additions and 0 deletions
|
@ -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:
|
||||
|
|
34
shell/navi.plugin.nu
Normal file
34
shell/navi.plugin.nu
Normal file
|
@ -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)
|
|
@ -13,6 +13,7 @@ impl Display for Shell {
|
|||
Self::Zsh => "zsh",
|
||||
Self::Fish => "fish",
|
||||
Self::Elvish => "elvish",
|
||||
Self::Nushell => "nushell",
|
||||
};
|
||||
|
||||
write!(f, "{s}")
|
||||
|
@ -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}");
|
||||
|
|
|
@ -11,6 +11,7 @@ pub enum Shell {
|
|||
Zsh,
|
||||
Fish,
|
||||
Elvish,
|
||||
Nushell
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue