improved z.sh completion for yash

This commit is contained in:
Rudis Muiznieks 2025-03-19 09:12:46 -05:00
parent 7cfe2b103e
commit d446bf51c4
Signed by: rudism
GPG key ID: CABF2F86EF7884F9

View file

@ -1,3 +1,6 @@
# shellcheck shell=sh
# shellcheck disable=SC2001 disable=SC2034 disable=SC2046 disable=2164
JUMP_LIST=~/.config/z/jump_list
_z_exec() {
@ -14,10 +17,15 @@ function completion/z {
) #<#
command -f completion//parseoptions -n
if [ -z "$ARGOPT" ] || [ "$ARGOPT" = "r" ]; then
complete -T $(_z_exec "select alias from jump_list")
elif [ "$ARGOPT" = "-" ]; then
argnum="${WORDS[#]}"
if [ "$ARGOPT" = "-" ] && [ "$argnum" -eq 1 ]; then
command -f completion//completeoptions
elif [ -z "$ARGOPT" ] && [ "$argnum" -eq 1 ]; then
complete -T $(_z_exec "select alias from jump_list")
elif [ "$ARGOPT" = "r" ] && [ "$argnum" -eq 2 ]; then
complete -T $(_z_exec "select alias from jump_list")
elif [ "${WORDS[2]}" = "-a" ] && [ "$argnum" -eq 3 ]; then
complete -T -S '/' -d
fi
}
@ -46,7 +54,7 @@ _z_add() {
echo "Directory not found: $dir"
return 1
fi
fullpath=$(cd "$dir"; pwd)
fullpath=$(realpath "$dir")
if [ ! -d "$fullpath" ]; then
echo "Could not change to directory: $fullpath"
return 1