scripts/lib/next-in-path.zsh
Alexander Gehrke e43c38c529 xdg-wrappers: add mbsync, make wrappers use next-in-path
The new next-in-path utility function finds the next entry for the
wrapped name in PATH after the called script, instead of hardcoding the
usual location for a system install.
2021-12-02 22:41:21 +01:00

13 lines
299 B
Bash

# find next entry in PATH for wrapper scripts
# Usage: next-in-path <program name> <current $0>
next-in-path() {
entries=( $(which -a $1) )
index=${entries[(ie)$2]}
if [[ $index -le ${#entries} ]]; then
# found $0, use next entry
echo $entries[$((index + 1))]
else
echo $entries[1]
fi
}