Debian Codegraph @

btest-progress

raw
1 #! /usr/bin/env bash
2
3 function usage {
4 cat <<EOF >&2
5 usage: $(basename "$0") [-q] [-T] <message>
6
7 -q: Do not print message to standard output or standard error.
8 -T: Do not include timestamp on standard error message.
9
10 EOF
11 exit 1
12 }
13
14 ### Main.
15
16 quiet=0
17 time=1
18
19 while getopts ":qT" opt; do
20 case $opt in
21 q)
22 quiet=1
23 shift
24 ;;
25 T)
26 time=0
27 shift
28 ;;
29 *)
30 usage
31 ;;
32 esac
33 done
34
35 test $# != 0 || usage
36
37 msg="[btest] -- $*"
38
39 if [ "${quiet}" -eq 0 ]; then
40 echo "${msg}"
41 if [ "${time}" -eq 0 ]; then
42 echo "${msg}" >&2
43 else
44 echo "${msg} -- $(date -u +'%Y-%m-%dT%H:%M:%S.%3NZ') " >&2
45 fi
46 fi
47
48 TIME=$(python3 -c 'import time; print(int(time.time() * 1e9))')
49 file=$(mktemp ".progress.${TIME}.XXXXXX") || exit 1
50 echo "$@" >>"${file}"