git://git.iain.cx/iain
/
profile.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fugitive plugin.
[profile.git]
/
opt
/
bin
/
find_working
diff --git
a/opt/bin/find_working
b/opt/bin/find_working
index
cbbd82d
..
454e365
100755
(executable)
--- a/
opt/bin/find_working
+++ b/
opt/bin/find_working
@@
-2,7
+2,9
@@
#
# find_working: Find a version of some tool in the PATH which actually runs.
# Usage: find_working [options] <prog>
#
# find_working: Find a version of some tool in the PATH which actually runs.
# Usage: find_working [options] <prog>
-# Options: -a <args> Use arguments to test executable files. Default --help.
+# Options: -A Don't test arguments to executable files.
+# -a <args> Use arguments to test executable files. Default --help.
+# -g <re> Search string in <args> output. Default <prog>.
# -q Don't print path to prog. Just exit 0 if found.
# -x Don't try to execute unreadable files. Assume success.
# -X Don't try to execute unreadable files. Assume failure.
# -q Don't print path to prog. Just exit 0 if found.
# -x Don't try to execute unreadable files. Assume success.
# -X Don't try to execute unreadable files. Assume failure.
@@
-11,9
+13,12
@@
args="-h -? --help"
quiet=0
unreadable=
args="-h -? --help"
quiet=0
unreadable=
-while getopts ":a:qxX" opt; do
+re=
+while getopts ":Aa:g:qxX" opt; do
case $opt in
case $opt in
+ A) args="";;
a) args="$OPTARG";;
a) args="$OPTARG";;
+ g) re="$OPTARG";;
q) quiet=1;;
x) unreadable=0;;
X) unreadable=1;;
q) quiet=1;;
x) unreadable=0;;
X) unreadable=1;;
@@
-24,23
+29,34
@@
shift $((OPTIND-1))
prog="$1"; shift
if [ -z "$prog" ]; then
echo >&2 "Usage: find_working [options] <prog>"
prog="$1"; shift
if [ -z "$prog" ]; then
echo >&2 "Usage: find_working [options] <prog>"
- echo >&2 "Options: -a <args> Use arguments to test executable files. Default --help."
+ echo >&2 "Options: -A Don't test arguments to executable files."
+ echo >&2 " -a <args> Use arguments to test executable files. Default --help."
+ echo >&2 " -g <re> Search string in <args> output. Default <prog>."
echo >&2 " -q Don't print path to prog. Just exit 0 if found."
echo >&2 " -x Don't try to execute unreadable files. Assume success."
echo >&2 " -X Don't try to execute unreadable files. Assume failure."
exit 1
fi
echo >&2 " -q Don't print path to prog. Just exit 0 if found."
echo >&2 " -x Don't try to execute unreadable files. Assume success."
echo >&2 " -X Don't try to execute unreadable files. Assume failure."
exit 1
fi
+[ -z "$re" ] && re="\\b$prog\\b"
+
+# Default args contain -? which might be interpreted as a glob.
+set -o noglob
+
ret=
for path in ${PATH//:/ }; do
[ -x "$path/$prog" ] || continue
if [ -r "$path/$prog" ]; then
ret=
for path in ${PATH//:/ }; do
[ -x "$path/$prog" ] || continue
if [ -r "$path/$prog" ]; then
- ldd "$path/$prog" 2>/dev/null | grep "not found" >/dev/null && continue
+ if [ -n "$args" ]; then
+ "$path/$prog" $args 2>&1 | grep "$re" >/dev/null || continue
+ else
+ ldd "$path/$prog" 2>/dev/null | grep "not found" >/dev/null && continue
+ fi
ret="$path/$prog"
break
elif [ -z "$unreadable" ]; then
ret="$path/$prog"
break
elif [ -z "$unreadable" ]; then
- "$path/$prog" $args 2>&1 | grep "
$prog
" >/dev/null || continue
+ "$path/$prog" $args 2>&1 | grep "
$re
" >/dev/null || continue
ret="$path/$prog"
break
elif [ $unreadable = 0 ]; then
ret="$path/$prog"
break
elif [ $unreadable = 0 ]; then