From 1bf78cbfb4fc03bc1b4b82a8927abec71896dadf Mon Sep 17 00:00:00 2001 From: Bahex Date: Sun, 5 Jan 2025 07:26:16 +0300 Subject: [PATCH] make nushell init script more idiomatic --- templates/nushell.txt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/templates/nushell.txt b/templates/nushell.txt index 90d5cba..a131efe 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -39,13 +39,14 @@ if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) { # # Jump to a directory using only keywords. -def --env --wrapped __zoxide_z [...rest:string] { - let arg0 = ($rest | append '~').0 - let arg0_is_dir = (try {$arg0 | path expand | path type}) == 'dir' - let path = if (($rest | length) <= 1) and ($arg0 == '-' or $arg0_is_dir) { - $arg0 - } else { - (zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n") +def --env --wrapped __zoxide_z [...rest: string] { + let path = match $rest { + [] => {'~'}, + [ '-' ] => {'-'}, + [ $arg ] if ($arg | path type) == 'dir' => {$arg} + _ => { + zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n" + } } cd $path {%- if echo %}