summaryrefslogtreecommitdiff
path: root/infloop
blob: dde7c868c66e7e008494e93b1c4e26dd96418428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash

MUSTBETRUE=y
unset MUSTBEFALSE
count=1
for i in $@; do
  count=$(printf "%s + 1\n" "$count" | bc)
  [ -n "$BUFFERREAD" ] && BUFFERTIME="$i" && unset BUFFERREAD && continue
  case "$i" in
    "-t")
      MUSTBETRUE=y
      unset MUSTBEFALSE
      ;;
    "-f")
      MUSTBEFALSE=y
      unset MUSTBETRUE
      ;;
    "-c")
      break 2
      ;;
    "-b")
      BUFFERREAD="y"
      ;;
    "-*")
      printf "Unsupported argument. Please use -t if exit on true, and -f if exit on false.\n"
      exit 1
  esac
done

if [ $# -ge $count ]; then
  COMMAND="${@:$count}"
else
  printf "No command given!\n" && exit 1
fi

while true; do
  if [ "$MUSTBEFALSE" ]; then
    $COMMAND || exit 0
  else
    $COMMAND && exit 0
  fi
  sleep "${BUFFERTIME:-1}"
done