diff options
author | EuAndreh <eu@euandre.org> | 2024-05-03 15:23:07 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-05-03 15:23:07 -0300 |
commit | 05a6b45d46bd1c8243f1a60208147a561e807b68 (patch) | |
tree | 8e2facf44cb066d345f31c6e8e8566f3cc739bb6 | |
parent | etc/sh/rc: Split exporting $N and $MAKEFLAGS (diff) | |
download | dotfiles-05a6b45d46bd1c8243f1a60208147a561e807b68.tar.gz dotfiles-05a6b45d46bd1c8243f1a60208147a561e807b68.tar.xz |
bin/statusconv: Utility to coerce programs to behave correctly
-rwxr-xr-x | bin/statusconv | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/bin/statusconv b/bin/statusconv new file mode 100755 index 0000000..9bc858b --- /dev/null +++ b/bin/statusconv @@ -0,0 +1,50 @@ +#!/bin/sh +set -eu + + +FROM_N='' +TO_N='' +for flag in "$@"; do + case "$flag" in + *[0-9]:*[0-9]) + X="$(printf '%s' "$flag" | cut -d ':' -f1)" + Y="$(printf '%s' "$flag" | cut -d ':' -f2)" + FROM_N="$FROM_N $X" + TO_N="$TO_N $Y" + shift + ;; + *) + break + ;; + esac +done + + +if [ "$1" = '--' ]; then + shift +fi + +STATUS=0 +"$@" || STATUS=$? + +FOUND=false +I=-1 +for from in $FROM_N; do + I=$((I + 1)) + if [ "$from" = "$STATUS" ]; then + FOUND=true + break + fi +done + +if [ "$FOUND" = false ]; then + exit "$STATUS" +fi + +J=-1 +for to in $TO_N; do + J=$((J + 1)) + if [ "$J" = "$I" ]; then + exit "$to" + fi +done |