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