diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-04 11:34:30 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-04 11:34:30 +1200 |
commit | ba0a646be7f8ca36dfd6e5f6e0c5fdf3bdc14f91 (patch) | |
tree | 5b0a2ca97f493a1de644a28c23089cdec3e53bb9 /bin/igex | |
parent | Make d2u(1) and u2d(1) error out on no args (diff) | |
download | dotfiles-ba0a646be7f8ca36dfd6e5f6e0c5fdf3bdc14f91.tar.gz dotfiles-ba0a646be7f8ca36dfd6e5f6e0c5fdf3bdc14f91.zip |
Change igex(1) into POSIX sh, simplify
Diffstat (limited to 'bin/igex')
-rwxr-xr-x | bin/igex | 88 |
1 files changed, 9 insertions, 79 deletions
@@ -1,82 +1,12 @@ -#!/usr/bin/env bash +#!/bin/sh # Run a command and ignore specified exit values. -self=igex - -# Print usage information -usage() { - printf '%s: usage: %s [-hv] -i IGNORE1[,IGNORE2...] [--] COMMAND [ARG1...]\n' \ - "$self" "$self" -} - -# Array with exit values to ignore -declare -a ignores -ignores=() - -# Flag for whether to print diagnostics to stderr or not; defaults to off -declare -i verbose -verbose=0 - -# Process options -while getopts 'hvi:' opt ; do - case $opt in - - # -h: Print help - h) - usage - exit 0 - ;; - - # -v: Print diagnostics to stderr - v) - verbose=1 - ;; - - # Specify the comma-delimited signals to ignore - i) - IFS=, read -a ignores < <(printf '%s\n' "$OPTARG") - ;; - - # Unknown option - \?) - usage >&2 - exit 2 - ;; - esac -done -shift "$((OPTIND-1))" - -# Check we have at least one ignore value -if ! ((${#ignores[@]})) ; then - usage >&2 - exit 2 -fi - -# Check that all the ignore values are non-zero -for ignore in "${ignores[@]}" ; do - ((ignore != 0)) && continue - usage >&2 - exit 2 -done - -# Check we have some arguments left to run a command -if ! (($#)) ; then - usage >&2 - exit 2 -fi - -# Run the command and save its exit value +igs=$1, +shift "$@" -ret=$? - -# Iterate through the ignored exit values and reset the exit value to 0 if it -# matches any of them, including a warning to stderr if -v was specified -for ignore in "${ignores[@]}" ; do - ((ret != ignore)) && continue - ((verbose)) && printf '%s: Ignoring exit value %u\n' \ - "$self" "$ignore" >&2 - ret=0 - break +ex=$? +while [ -n "$igs" ] ; do + ig=${igs%%,*} + [ "$((ig == ex))" -eq 1 ] && exit 0 + igs=${igs#*,} done - -# Exit with the determined value -exit "$ret" +exit "$ex" |