sane-which: handle relative symlinks

This commit is contained in:
2024-02-28 18:16:08 +00:00
parent 9e504676bd
commit 7c22b59b9d

View File

@@ -6,12 +6,15 @@
cur="$1"
next="$(which "$cur")"
getExists() {
[ -e "$1" ] && echo "$1"
}
getSymlinked() {
# test if $cur is a symlink
# TODO: handle relative symlinks too!
local next_
next_="$(readlink "$cur")"
[ "$?" -eq 0 ] && echo "$next_"
[ "$?" -eq 0 ] && (getExists "$next_" || getExists "$(dirname "$cur")/$next_" || echo "$next_")
}
getWrapped() {