aliasrc | improve se() (#1433)

* 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.

* capture sub-directories too
This commit is contained in:
Emre AKYÜZ 2025-02-28 20:11:57 +01:00 committed by GitHub
parent 4606e9156a
commit e2d787992e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 \