dotfiles/bin/lbin

28 lines
554 B
Bash
Executable File

#!/usr/bin/env bash
set -e
if [[ -z "$1" || "$1" == "--help" || "$1" == "-h" ]]; then
cat <<EOF
Usage: $(basename $0) [ prog ]
Searches recursively for 'bin/prog' executable from current directory and
parent directories, and executes it if successfully found.
EOF
exit
fi
prog="$1"
shift
rootdir="$(pwd)"
while [[ "$rootdir" != "" && ! -x "$rootdir/bin/$prog" ]]; do
rootdir=${rootdir%/*}
done
if [[ ! -x "$rootdir/bin/$prog" ]]; then
echo "No executable found in bin of parent directories."
exit 1
fi
"$rootdir/bin/$prog" "$@"