From 51403167645ee391d6caf0f20860c1629d657442 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Thu, 23 Nov 2023 19:50:26 +0100 Subject: [PATCH] More efficient cdg --- nushell/config/gclone.nu | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/nushell/config/gclone.nu b/nushell/config/gclone.nu index 2393836..ed3c609 100644 --- a/nushell/config/gclone.nu +++ b/nushell/config/gclone.nu @@ -1,21 +1,19 @@ # gclone aliases -def _gclone_dirs [] { - let slashes = ($env.GCLONE_PATH | split row "/" | length) + 3 - _ls ($env.GCLONE_PATH + "/**") - | each { $in.name } - | where { ($in | split row "/" | length) <= $slashes } - | each { $in | split row "/" | last } +def _gclone_dirs [] { + _ls ($env.GCLONE_PATH + "/*") + | append (_ls ($env.GCLONE_PATH + "/*/*")) + | append (_ls ($env.GCLONE_PATH + "/*/*/*")) + | each { $in.name | path basename } | sort | uniq } def --env cdg [key: string@_gclone_dirs] { - - let slashes = ($env.GCLONE_PATH | split row "/" | length) + 3 - - let dir = _ls ($env.GCLONE_PATH + "/**") - | where { $in != null and ($in.name | split row "/" | length) <= $slashes and ($in.name | path basename) == $key } + let dir = _ls ($env.GCLONE_PATH + "/*") + | append (_ls ($env.GCLONE_PATH + "/*/*")) + | append (_ls ($env.GCLONE_PATH + "/*/*/*")) + | where { $in != null and ($in.name | path basename) == $key } match ($dir | length) { @@ -38,6 +36,8 @@ def --env cdg [key: string@_gclone_dirs] { (ansi reset) + " multiple entries found, please select one" ) + echo $dir + print ( (ansi --escape 'A') + (ansi attr_bold) + "Enter your choice: " + (ansi reset)