From 5e3dac2efd3703bf556f67585f0e45cd528ce379 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Tue, 21 Oct 2025 15:45:31 +1100 Subject: feat: nu ≥ 0.106.0 support commandline accept (#2957) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Summary Adjust the Nushell script to check the version and enable accept support when Nushell 0.106.0 or greater is found. See: https://github.com/nushell/nushell/pull/16193 ## Checks - [x] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle - [x] I have checked that there are no existing pull requests for the same thing --- .../atuin/src/command/client/search/interactive.rs | 4 +-- crates/atuin/src/shell/atuin.nu | 42 ++++++++++++++++------ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/crates/atuin/src/command/client/search/interactive.rs b/crates/atuin/src/command/client/search/interactive.rs index f50568e7..bcf456a4 100644 --- a/crates/atuin/src/command/client/search/interactive.rs +++ b/crates/atuin/src/command/client/search/interactive.rs @@ -1418,7 +1418,7 @@ pub async fn history( if accept && matches!( Shell::from_env(), - Shell::Zsh | Shell::Fish | Shell::Bash | Shell::Xonsh + Shell::Zsh | Shell::Fish | Shell::Bash | Shell::Xonsh | Shell::Nu ) { command = String::from("__atuin_accept__:") + &command; @@ -1438,7 +1438,7 @@ pub async fn history( } else if accept && matches!( Shell::from_env(), - Shell::Zsh | Shell::Fish | Shell::Bash | Shell::Xonsh + Shell::Zsh | Shell::Fish | Shell::Bash | Shell::Xonsh | Shell::Nu ) { command = String::from("__atuin_accept__:") + &command; diff --git a/crates/atuin/src/shell/atuin.nu b/crates/atuin/src/shell/atuin.nu index 0e4ff691..190f3117 100644 --- a/crates/atuin/src/shell/atuin.nu +++ b/crates/atuin/src/shell/atuin.nu @@ -46,17 +46,37 @@ let _atuin_pre_prompt = {|| } def _atuin_search_cmd [...flags: string] { - [ - $ATUIN_KEYBINDING_TOKEN, - ([ - `with-env { ATUIN_LOG: error, ATUIN_QUERY: (commandline) } {`, - 'commandline edit', - '(run-external atuin search', - ($flags | append [--interactive] | each {|e| $'"($e)"'}), - ' e>| str trim)', - `}`, - ] | flatten | str join ' '), - ] | str join "\n" + if (version).minor >= 106 or (version).major > 0 { + [ + $ATUIN_KEYBINDING_TOKEN, + ([ + `with-env { ATUIN_LOG: error, ATUIN_QUERY: (commandline), ATUIN_SHELL: nu } {`, + ([ + 'let output = (run-external atuin search', + ($flags | append [--interactive] | each {|e| $'"($e)"'}), + 'e>| str trim)', + ] | flatten | str join ' '), + 'if ($output | str starts-with "__atuin_accept__:") {', + 'commandline edit --accept ($output | str replace "__atuin_accept__:" "")', + '} else {', + 'commandline edit $output', + '}', + `}`, + ] | flatten | str join "\n"), + ] + } else { + [ + $ATUIN_KEYBINDING_TOKEN, + ([ + `with-env { ATUIN_LOG: error, ATUIN_QUERY: (commandline) } {`, + 'commandline edit', + '(run-external atuin search', + ($flags | append [--interactive] | each {|e| $'"($e)"'}), + ' e>| str trim)', + `}`, + ] | flatten | str join ' '), + ] + } | str join "\n" } $env.config = ($env | default {} config).config -- cgit v1.3.1