aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-03-21 06:18:26 -0300
committerEuAndreh <eu@euandre.org>2023-03-21 06:18:26 -0300
commit60038569c537b34c0f09db260effcb34a2000a9f (patch)
treef67ad767dd4c14a8002226996afd4ee11b9f456b
parentetc/guix/system.scm: Better handling of binfmt architectures (diff)
downloaddotfiles-60038569c537b34c0f09db260effcb34a2000a9f.tar.gz
dotfiles-60038569c537b34c0f09db260effcb34a2000a9f.tar.xz
bin/untill: Add support for "-m MAX" option
-rwxr-xr-xbin/untill20
1 files changed, 14 insertions, 6 deletions
diff --git a/bin/untill b/bin/untill
index 030f921..738b5bb 100755
--- a/bin/untill
+++ b/bin/untill
@@ -4,7 +4,7 @@ set -eu
usage() {
cat <<-'EOF'
Usage:
- until [-n SECONDS] -- COMMAND...
+ until [-m MAX] [-n SECONDS] -- COMMAND...
until -h
EOF
}
@@ -15,11 +15,12 @@ help() {
Options:
-n SECONDS the amount of seconds to sleep between
attempts (default: 5)
+ -m MAX the maximum number of attempts (default: unlimited)
-h, --help show this message
- Runs COMMAND until it eventually succeeds. Sleep SECONDS
- between attempts.
+ Runs COMMAND until it eventually succeeds, trying atmost MAX
+ times. Sleep SECONDS between attempts.
Examples:
@@ -29,10 +30,10 @@ help() {
$ until guix home build home.scm
- Try to build until a new version is successfull,
+ Try atmost 10 timex to build until a new version is successfull,
waiting 30 seconds between attempts:
- $ until -n 30 -- x git pull AND make
+ $ until -m 10 -n 30 -- x git pull AND make
EOF
}
@@ -53,8 +54,11 @@ for flag in "$@"; do
done
_SECONDS=5
-while getopts 'n:h' flag; do
+while getopts 'm:n:h' flag; do
case "$flag" in
+ m)
+ MAX="$OPTARG"
+ ;;
n)
_SECONDS="$OPTARG"
;;
@@ -79,5 +83,9 @@ while true; do
if "$@"; then
break
fi
+ if [ -n "${MAX:-}" ] && [ "$ATTEMPT" -gt "$MAX" ]; then
+ printf 'Maximum number of attempts reached: %s.\n' "$MAX" >&2
+ exit 1
+ fi
sleep "$_SECONDS"
done