make nushell init script more idiomatic

This commit is contained in:
Bahex 2025-01-05 07:26:16 +03:00
parent d99d82f141
commit 1bf78cbfb4
1 changed files with 8 additions and 7 deletions

View File

@ -39,13 +39,14 @@ if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
# #
# Jump to a directory using only keywords. # Jump to a directory using only keywords.
def --env --wrapped __zoxide_z [...rest:string] { def --env --wrapped __zoxide_z [...rest: string] {
let arg0 = ($rest | append '~').0 let path = match $rest {
let arg0_is_dir = (try {$arg0 | path expand | path type}) == 'dir' [] => {'~'},
let path = if (($rest | length) <= 1) and ($arg0 == '-' or $arg0_is_dir) { [ '-' ] => {'-'},
$arg0 [ $arg ] if ($arg | path type) == 'dir' => {$arg}
} else { _ => {
(zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n") zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
}
} }
cd $path cd $path
{%- if echo %} {%- if echo %}