qb: Update the exists function.

This commit is contained in:
orbea 2020-01-14 10:20:07 -08:00
parent a6b114e423
commit d89b7f93b2

View file

@ -23,22 +23,29 @@ exists()
while [ $# -gt 0 ]; do
arg="$1"
shift 1
case "$arg" in ''|*/) continue ;; esac
x="${arg##*/}"
z="${arg%/*}"
[ ! -f "$z/$x" ] || [ ! -x "$z/$x" ] && [ "$z/$x" = "$arg" ] &&
continue
[ "$x" = "$z" ] && [ -x "$z/$x" ] && [ ! -f "$arg" ] && z=
p=":$z:$PATH"
while [ "$p" != "${p#*:}" ]; do
p="${p#*:}"
d="${p%%:*}"
if [ -f "$d/$x" ] && [ -x "$d/$x" ]; then
printf %s\\n "$d/$x"
v=0
break
fi
done
case "$arg" in
''|*/ )
:
;;
*/* )
if [ -f "$arg" ] && [ -x "$arg" ]; then
printf %s\\n "$arg"
v=0
fi
;;
* )
p=":$PATH"
while [ "$p" != "${p#*:}" ]; do
p="${p#*:}"
d="${p%%:*}/$arg"
if [ -f "$d" ] && [ -x "$d" ]; then
printf %s\\n "$d"
v=0
break
fi
done
;;
esac
done
return $v
}