aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-04 11:34:30 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-04 11:34:30 +1200
commitba0a646be7f8ca36dfd6e5f6e0c5fdf3bdc14f91 (patch)
tree5b0a2ca97f493a1de644a28c23089cdec3e53bb9
parentMake d2u(1) and u2d(1) error out on no args (diff)
downloaddotfiles-ba0a646be7f8ca36dfd6e5f6e0c5fdf3bdc14f91.tar.gz
dotfiles-ba0a646be7f8ca36dfd6e5f6e0c5fdf3bdc14f91.zip
Change igex(1) into POSIX sh, simplify
-rwxr-xr-xbin/igex88
-rw-r--r--man/man1/igex.117
2 files changed, 16 insertions, 89 deletions
diff --git a/bin/igex b/bin/igex
index 0bd36cc0..1ca23ecf 100755
--- a/bin/igex
+++ b/bin/igex
@@ -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"
diff --git a/man/man1/igex.1 b/man/man1/igex.1
index 1c2396d4..731041c6 100644
--- a/man/man1/igex.1
+++ b/man/man1/igex.1
@@ -1,19 +1,16 @@
-.TH IGEX 1 "February 2016" "Manual page for igex"
+.TH IGEX 1 "August 2016" "Manual page for igex"
.SH NAME
.B igex
\- run a command, ignoring specified error exit values
.SH USAGE
-.B igex [-hv] -i IGNORE1[,IGNORE2...] [--] COMMAND [ARG1...]
+.B igex VAL1[,VAL2,VAL3,...] COMMAND [ARG1...]
.SH DESCRIPTION
Runs the given command and checks its exit value. If it matches any of the
-ignored values given in -i, exits 0. Otherwise, exits with the command's exit
-value as normal.
+ignored values given in the first argument, exits 0. Otherwise, exits with the
+command's exit value as normal.
.P
-Option -h gives help, option -v turns on verbose output, option -i specifies an
-the signals to ignore, comma-delimited; you must specify at least one non-zero
-integer.
-.P
- $ igex -i1 false
- $ igex -v -i24 rsync source dest
+ $ igex 1 false
+ $ igex 24 rsync source dest
+ $ igex 8,9 mycmd
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>