From 2d79fbeb411db1233eb33b989f492f5cf8cfd79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Mon, 2 Sep 2024 16:17:45 +0300 Subject: [PATCH 1/2] aliasrc | improve se() 1. Remove external commands like find. 2. Remove extensions and path (if present) from the names in fzf. 3. Only open Nvim if there is a selection. Do all of these without using find, sed, grep. - First line creates an array with the files in the scripts directory. - Second line removes path (:t) and the extensions (:r) from the scripts. - [[ "${c}" ]] checks if this variable is non-empty. - ${${(M)s:#*/${c}*}[1]} (M) enables "match" mode. :# anchors the pattern to the start of each array element. */${c}* matches any path containing the selected basename. [1] selects the first matching item. --- .config/shell/aliasrc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.config/shell/aliasrc b/.config/shell/aliasrc index 75327bf792..356e3dfedd 100644 --- a/.config/shell/aliasrc +++ b/.config/shell/aliasrc @@ -14,9 +14,10 @@ for command in mount umount sv pacman updatedb su shutdown poweroff reboot ; do done; unset command se() { - choice="$(find ~/.local/bin -mindepth 1 -printf '%P\n' | fzf)" - [ -f "$HOME/.local/bin/$choice" ] && $EDITOR "$HOME/.local/bin/$choice" - } + s=("${HOME}/.local/bin/"*) + c="$(print -lnr ${s:t:r} | fzf)" + [[ "${c}" ]] && "${EDITOR}" ${${(M)s:#*/${c}*}[1]} +} # Verbosity and settings that you pretty much just always are going to want. alias \ From bfe1c0a5928cb04eeb6bbe2b5ba6d4bfdf8ef054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sat, 7 Sep 2024 15:52:54 +0300 Subject: [PATCH 2/2] capture sub-directories too --- .config/shell/aliasrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/shell/aliasrc b/.config/shell/aliasrc index 356e3dfedd..5347fcd172 100644 --- a/.config/shell/aliasrc +++ b/.config/shell/aliasrc @@ -14,7 +14,7 @@ for command in mount umount sv pacman updatedb su shutdown poweroff reboot ; do done; unset command se() { - s=("${HOME}/.local/bin/"*) + s=("${HOME}/.local/bin/"**/*(.)) c="$(print -lnr ${s:t:r} | fzf)" [[ "${c}" ]] && "${EDITOR}" ${${(M)s:#*/${c}*}[1]} }