1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2025-02-05 07:43:22 -08:00

add silent flag from Ubuntu to witch

This commit is contained in:
Connor Olding 2024-07-13 02:57:14 -07:00
parent 466722d107
commit b7b1e03a69

View file

@ -4,10 +4,11 @@
### this is a personal rewrite of `which` from Debian. ### this is a personal rewrite of `which` from Debian.
### the original version didn't run on certain shells, ### the original version didn't run on certain shells,
### and inherited inconsistent behaviors from getopts. ### and inherited inconsistent behaviors from getopts.
### the silent (`-s`) flag from Ubuntu has been added.
set -ef set -ef
all=0 all=0 silent=0
for flag; do for flag; do
case "$flag" in case "$flag" in
(--) shift; break;; (--) shift; break;;
@ -16,6 +17,7 @@ for flag; do
while flag="${flag#?}"; [ -n "$flag" ]; do while flag="${flag#?}"; [ -n "$flag" ]; do
case "$flag" in case "$flag" in
(a*) all=1;; (a*) all=1;;
(s*) silent=1;;
(*) (*)
printf >&2 'Illegal option: -%.1s\n' "$flag" printf >&2 'Illegal option: -%.1s\n' "$flag"
printf 'Usage: %s\n' "$0 [-a] args" printf 'Usage: %s\n' "$0 [-a] args"
@ -28,13 +30,19 @@ done
[ "$#" = 0 ] && res=1 || res=0 [ "$#" = 0 ] && res=1 || res=0
if [ "$silent" = 0 ]; then
puts() { printf %s\\n "$@"; }
else
puts() { :; }
fi
IFS=: IFS=:
for prog; do for prog; do
err=1 err=1
case "$prog" in case "$prog" in
(*/*) (*/*)
if [ -f "$prog" ] && [ -x "$prog" ]; then if [ -f "$prog" ] && [ -x "$prog" ]; then
printf %s\\n "$prog" puts "$prog"
err=0 err=0
fi;; fi;;
(*) (*)
@ -42,7 +50,7 @@ for prog; do
for sub; do for sub; do
[ -n "$sub" ] || sub=. [ -n "$sub" ] || sub=.
if [ -f "$sub/$prog" ] && [ -x "$sub/$prog" ]; then if [ -f "$sub/$prog" ] && [ -x "$sub/$prog" ]; then
printf %s\\n "$sub/$prog" puts "$sub/$prog"
err=0 err=0
[ "$all" = 1 ] || break [ "$all" = 1 ] || break
fi fi