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