atuin icon indicating copy to clipboard operation
atuin copied to clipboard

nushell: atuin should not always trigger on ⬆️

Open freijon opened this issue 1 year ago • 3 comments

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.

freijon avatar Jun 02 '23 08:06 freijon

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?

alextremblay avatar Jun 13 '23 13:06 alextremblay

This issue leads to a pretty terrible experience, should we disable the up arrow by default for Nushell until this can be fixed?

arcuru avatar Oct 25 '23 21:10 arcuru

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?

ellie avatar Oct 25 '23 22:10 ellie

FYI the default keybinding in nu is this

    {
        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.

from-nibly avatar Feb 14 '24 19:02 from-nibly

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') }
                ]
            }
        }
    )
)

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).

remmycat avatar Feb 25 '24 18:02 remmycat

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" } } ]

from-nibly avatar Feb 25 '24 18:02 from-nibly

Awesome - I went ahead and created a PR before I forget - let me know if the fix works for you!

remmycat avatar Feb 25 '24 19:02 remmycat

Oh, and just for the next person being confused, the original issue description is probably meant to say Type "math" and press tab. since the default tab-autocompletion opens as a menu with options.

At least that is how I could reproduce the behaviour in menus.

remmycat avatar Feb 25 '24 19:02 remmycat

I copied the snippet from your comment and that seems to be working!

Jordan Davidson

On Sunday, February 25th, 2024 at 12:16 PM, Remmy Cat Stock @.***> wrote:

Oh, and just for the next person being confused, the original issue description is probably meant to say Type "math" and press tab. since the default tab-autocompletion opens as a menu with options.

At least that is how I could reproduce the behaviour in menus.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

from-nibly avatar Feb 26 '24 17:02 from-nibly

Even though this PR is merged the init file has commented code for the binding with a link to this PR. Is that expected?

# The up arrow keybinding has surprising behavior in Nu, and is disabled by default.
# See https://github.com/atuinsh/atuin/issues/1025 for details

msminhas93 avatar Mar 16 '24 18:03 msminhas93

@msminhas93 The text should indeed not be generated anymore, no. Make sure that you have version 18.1.0 installed (or a newer commit).

Since the fix is part of what the init script outputs, you will not get the new version of the init file unless you manually recreate it after updating to the latest version. Note that this will overwrite manual changes you might have made to the init file.

As per the script in the Readme, assuming you haven't changed the paths:

atuin init nu | save -f ~/.local/share/atuin/init.nu

remmycat avatar Mar 16 '24 20:03 remmycat

Thanks that was it!

msminhas93 avatar Mar 16 '24 22:03 msminhas93