From 5d84c43a0c1df3222d9222db454111ce7d7eef57 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Thu, 3 Apr 2025 21:12:22 +0300 Subject: [PATCH] feat: _ command for nushell for retrieving the last command --- modules/common/nushell/config.nu | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/common/nushell/config.nu b/modules/common/nushell/config.nu index 87c7c42..f255470 100644 --- a/modules/common/nushell/config.nu +++ b/modules/common/nushell/config.nu @@ -158,9 +158,15 @@ $env.config.cursor_shape = { $env.config.hooks = { command_not_found: {||} - display_output: "table --expand" - env_change: {} - pre_execution: [ + + display_output: { + tee { table --expand | print } + | $env.last = $in + } + + env_change: {} + + pre_execution: [ { let prompt = commandline | str trim @@ -171,7 +177,13 @@ $env.config.hooks = { print $"(ansi title)($prompt) — nu(char bel)" } ] - pre_prompt: [] + + pre_prompt: [] +} + +# Retrieve the output of the last command. +def _ []: nothing -> any { + $env.last } $env.config.menus = [