Repository: atuinsh/atuin (language: rust)

Issue:
nushell: atuin should not always trigger on ⬆️
With the nushell integration the "Arrow up" key is used to browse the history with `atuin`.
However, I don't always want that. For example when I'm in "picker mode" of nushell.

Example:
Type "math" and press <TAB>. A menu with available math commands is shown that (normally) can be navigated with ⬆/⬇. However with the `atuin` integration, the ⬆ key closes the pick menu and shows the history with `atuin`.

The history should only show up when in normal prompt mode. Not when a menu is shown.


Discussion / hints:
hmmm... i think that might be a nushell bug. I think nushell should be overriding global keybinds like "up arrow" with local keybinds but isn't doing that.

Have you opened an issue in the nushell repo? if so, can you link to it here?
This issue leads to a pretty terrible experience, should we disable the up arrow by default for Nushell until this can be fixed?
> This issue leads to a pretty terrible experience, should we disable the up arrow by default for Nushell until this can be fixed?

I think that would probably be best, though hopefully their keybindings become more flexible soon 🙏  Are you happy to make the PR?
FYI the default keybinding in nu is this

```nu
    {
        name: move_up
        modifier: none
        keycode: up
        mode: [emacs, vi_normal, vi_insert]
        event: {
            until: [
                {send: historyhintcomplete }
                {send: menuup}
                {send: up}
            ]
        }
    }
```

I think the "until" is how you leverage "doing the right thing at the right time".  I don't know any more details than that.
I'm not sure where you copied this from, but the [default config](https://github.com/nushell/nushell/blob/c2992d5d8b8541b64e9fc1440ed2917fc9b757f7/crates/nu-utils/src/sample_config/default_config.nu#L457) seems to be this and hasn't changed in a while, except for formatting:

```nushell
        {
            name: move_up
            modifier: none
            keycode: up
            mode: [emacs, vi_normal, vi_insert]
            event: {
                until: [
                    {send: menuup}
                    {send: up}
                ]
            }
        }
```

You can find the `until` reference here: https://www.nushell.sh/book/line_editor.html#until-type

Based on this, I modified the commented out part in the init script
```nushell
$env.config = (
    $env.config | upsert keybindings (
        $env.config.keybindings
        | append {
            name: atuin
            modifier: none
            keycode: up
            mode: [emacs, vi_normal, vi_insert]
            event: {
                until: [
                    {send: menuup}
                    {send: executehostcommand cmd: (_atuin_search_cmd '--shell-up-key-binding') }
                ]
            }
        }
    )
)
```

This seems to work! I can navigate through menus and when not in one I'm opening atuin.
Maybe I'm missing something but I think this is the fix.

Basically it first tries to do the `menuup` action, if that fails (because we're not in a menu), it tries atuin.

I was thinking to add a `{send: up}` fallback at the end when atuin fails, but the docs make it sound like currently only the menu actions can fail in a way that makes the next "until" item fire.

And yeah, when I modify the command to produce a positive exit code, the current behaviour seems to be that it just silently stops or crashes in some way, and nu gives me a new line. Instead of going to the next action in the array (what I thought might happen).
That's great I will probably test drive this on Monday. -------- Original Message --------On 2/25/24 11:39 AM, Remmy Cat Stock  wrote:
I'm not sure where you copied this from, but the default config seems to be this and hasn't changed in a while, except for formatting:
        {
            name: move_up
            modifier: none
            keycode: up
            mode: [emacs, vi_normal, vi_insert]
            event: {
                until: [
                    {send: menuup}
                    {send: up}
                ]
            }
        }
You can find the until reference here: https://www.nushell.sh/book/line_editor.html#until-type
Based on this, I modified the commented out part in the init script
$env.config = (
    $env.config | upsert keybindings (
        $env.config.keybindings
        | append {
            name: atuin
            modifier: none
            keycode: up
            mode: [emacs, vi_normal, vi_insert]
            event: {
                until: [
                    {send: menuup}
                    {send: executehostcommand cmd: (_atuin_search_cmd '--shell-up-key-binding') }
                    {send: up}
                ]
            }
        }
    )
)
This seems to work! I can navigate through menus and when not in one I'm opening atuin.
Maybe I'm missing something but I think this might be the fix.
Basically it first tries to do the menuup action, if that fails (because we're not in a menu), it tries atuin.
I think the last line with {send: up} can maybe also be removed?
The docs make it sound like currently only the menu actions can fail in a way that makes the next "until" item fire. When I modify the command to produce a positive exit code, the current behaviour seems to be that it just stops or crashes in some way silently and nu gives me a new line, instead of going to the next action in the array.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
[
{
***@***.***": "http://schema.org",
***@***.***": "EmailMessage",
"potentialAction": {
***@***.***": "ViewAction",
"target": "https://github.com/atuinsh/atuin/issues/1025#issuecomment-1963024832",
"url": "https://github.com/atuinsh/atuin/issues/1025#issuecomment-1963024832",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
***@***.***": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]

Fix patch:
diff --git a/atuin/src/command/client/init.rs b/atuin/src/command/client/init.rs
index 9bff3fcc9b6..d9bad148c5c 100644
--- a/atuin/src/command/client/init.rs
+++ b/atuin/src/command/client/init.rs
@@ -56,20 +56,23 @@ impl Cmd {
     )
 )";
             const BIND_UP_ARROW: &str = r"
-# The up arrow keybinding has surprising behavior in Nu, and is disabled by default.
-# See https://github.com/atuinsh/atuin/issues/1025 for details
-# $env.config = (
-#     $env.config | upsert keybindings (
-#         $env.config.keybindings
-#         | append {
-#             name: atuin
-#             modifier: none
-#             keycode: up
-#             mode: [emacs, vi_normal, vi_insert]
-#             event: { send: executehostcommand cmd: (_atuin_search_cmd '--shell-up-key-binding') }
-#         }
-#     )
-# )
+$env.config = (
+    $env.config | upsert keybindings (
+        $env.config.keybindings
+        | append {
+            name: atuin
+            modifier: none
+            keycode: up
+            mode: [emacs, vi_normal, vi_insert]
+            event: {
+                until: [
+                    {send: menuup}
+                    {send: executehostcommand cmd: (_atuin_search_cmd '--shell-up-key-binding') }
+                ]
+            }
+        }
+    )
+)
 ";
             if !self.disable_ctrl_r {
                 println!("{BIND_CTRL_R}");


Test patch: