From 071969ada0f47f2b807c5955f0fd1829a5fe1f46 Mon Sep 17 00:00:00 2001 From: Ben Yang Date: Mon, 24 Jun 2024 18:50:29 +0800 Subject: [PATCH 1/2] mvp. --- shell/navi.plugin.nu | 34 ++++++++++++++++++++++++++++++++++ src/commands/shell.rs | 2 ++ src/common/shell.rs | 1 + tests/run | 1 + 4 files changed, 38 insertions(+) create mode 100644 shell/navi.plugin.nu diff --git a/shell/navi.plugin.nu b/shell/navi.plugin.nu new file mode 100644 index 0000000..f1c9f4c --- /dev/null +++ b/shell/navi.plugin.nu @@ -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) diff --git a/src/commands/shell.rs b/src/commands/shell.rs index ca64d0f..9b01272 100644 --- a/src/commands/shell.rs +++ b/src/commands/shell.rs @@ -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}"); diff --git a/src/common/shell.rs b/src/common/shell.rs index 331eb32..7e275e7 100644 --- a/src/common/shell.rs +++ b/src/common/shell.rs @@ -11,6 +11,7 @@ pub enum Shell { Zsh, Fish, Elvish, + Nushell } #[derive(Error, Debug)] diff --git a/tests/run b/tests/run index 9943763..3d57135 100755 --- a/tests/run +++ b/tests/run @@ -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 From afc4883bffe0b121d1d54aeef69f9c4e739ffcba Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 24 Jun 2024 23:23:33 +0800 Subject: [PATCH 2/2] updated doc. --- docs/installation.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/installation.md b/docs/installation.md index a9a2564..72a8e64 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -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: