improve next-in-path handling, fix line endings

This commit is contained in:
Alexander Gehrke 2026-01-11 15:33:53 +01:00
parent f546b49599
commit 31a59f0207
14 changed files with 62 additions and 48 deletions

View file

@ -2,12 +2,19 @@
# Usage: next-in-path <program name> <current $0>
typeset -U path
next-in-path() {
entries=( $(which -a $1) )
index=${entries[(ie)$2]}
local entries=( $(which -a $1) )
local index=${entries[(ie)$2]}
local result
if [[ $index -le ${#entries} ]]; then
# found $0, use next entry
echo $entries[$((index + 1))]
result=$entries[$((index + 1))]
else
echo $entries[1]
result=$entries[1]
fi
if [[ -n $result ]]; then
echo $result
else
return 1
fi
}