From 8904f22242ba6ca24e3db0b479d339bb455a980f Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Tue, 16 Jul 2024 10:59:54 -0700 Subject: [PATCH] rewrite short-flag parsing in `permit` --- sh/permit | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/sh/permit b/sh/permit index c2974bd..8a5a17a 100755 --- a/sh/permit +++ b/sh/permit @@ -53,22 +53,20 @@ permit() { ### @- conditionally set executable permissions on each of its argume done break;; - (-*) + (-?*) shift - case "${__permit_f#-}" in - (a) __permit_a=1;; # automatic (on) - (A) __permit_a=0;; # automatic (off) - (e) __permit_m=e;; # everything - (f) __permit_m=f;; # files only - (d) __permit_m=d;; # directories only - (?|-*) - printf >&2 'permit: %s\n' "unknown flag: $__permit_f" - return 64;; - (*) - set -- "${__permit_f%"${__permit_f#-?}"}" "-${__permit_f#-?}" "$@" - : $((__permit_n+=2)) - continue;; - esac;; + while __permit_f="${__permit_f#?}"; [ -n "$__permit_f" ]; do + case "${__permit_f}" in + (a*) __permit_a=1;; # automatic (on) + (A*) __permit_a=0;; # automatic (off) + (e*) __permit_m=e;; # everything + (f*) __permit_m=f;; # files only + (d*) __permit_m=d;; # directories only + (*) + printf >&2 'permit: unknown flag: -%.1s\n' "$__permit_f" + return 64;; + esac + done;; (*) shift