From 8725f85012f5cf19ce8b25c75a0d5f6cf059978a Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 13 Apr 2024 23:24:43 -0500 Subject: Add 'ok -' which allows to do ok without death --- ok | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ok b/ok index 058c98d..22aa7bb 100755 --- a/ok +++ b/ok @@ -2,6 +2,7 @@ QUIET=false NORUN=false +DIE=true FNEW=false _ARGS=true @@ -28,6 +29,12 @@ $(sed -n \ EOH } +die(){ + ec="$1"; shift + printf '%s\n' "$*" >&2 + exit $ec +} + procargs(){ $_ARGS || return 1 while getopts hqnxBf:C: OPT @@ -52,7 +59,7 @@ go(){ test -z "$1" && "$DEFAULT" for target do - if grep -q "$target" "$FRFILE" + if grep -q "$target" "$FRFILE" 2>/dev/null then if buildp "$target" \ "$(grep "$target" "$FRFILE" | cut -f3-)" then eval "$(grep "$target" "$FRFILE" | cut -f2-)" @@ -63,7 +70,7 @@ go(){ } dep(){ - _ARGS=false go "$@" + _ARGS=false go "$@" || exit "$((200 + $?))" } buildp(){ # buildp TARGET DEPENDENCIES... @@ -79,8 +86,13 @@ buildp(){ # buildp TARGET DEPENDENCIES... } ok(){ # ok COMMAND ARGS.. + case "$1" in (-) DIE=false; shift ;; esac $QUIET || printf >&2 '* %s\n' "$*" - $NORUN || "$@" || exit $((100 + $?)) + $NORUN || "$@"; ec="$?" + if $DIE && test $ec -ne 0 + then die $((100 + $?)) not ok + else return $ec + fi } quietly(){ "$@" >/dev/null 2>&1; } @@ -106,4 +118,4 @@ fr(){ # fr < TARGET JOB DEPS... done } -go "$@" +go "$@" && echo ok -- cgit 1.4.1-21-gabe81