1 | # shellcheck shell=bash
|
---|
2 | # $Id$
|
---|
3 |
|
---|
4 | set -e
|
---|
5 |
|
---|
6 | # Be sure that we know the target name
|
---|
7 | [[ -z $1 ]] && exit
|
---|
8 | TARGET=$1 # Remember the target build we are looking for
|
---|
9 | MAKE_PPID=$2
|
---|
10 |
|
---|
11 | declare -r CSI=$'\e[' # DEC terminology, Control Sequence Introducer
|
---|
12 | declare -r CURSOR_OFF=${CSI}$'?25l'
|
---|
13 | declare -r CURSOR_ON=${CSI}$'?25h'
|
---|
14 | declare -r ERASE_LINE=${CSI}$'2K'
|
---|
15 | declare -r FRAME_OPEN=${CSI}$'2G['
|
---|
16 | declare -r FRAME_CLOSE=${CSI}$'63G]'
|
---|
17 | declare -r TS_POSITION=${CSI}$'65G'
|
---|
18 | declare -r RESET_LINE=${CURSOR_OFF}${ERASE_LINE}${FRAME_OPEN}${FRAME_CLOSE}
|
---|
19 |
|
---|
20 | declare -r GRAPHIC_STR="| / - \\ + "
|
---|
21 | declare -i SEC=0 # Seconds accumulator
|
---|
22 | declare -i PREV_SEC=0
|
---|
23 |
|
---|
24 | # Prevent segfault on stripping phases
|
---|
25 | if [[ "$BASHBIN" = "/tools/bin/bash" ]] ; then
|
---|
26 | SLEEP=/tools/bin/sleep
|
---|
27 | elif [ -x /bin/sleep ] ; then
|
---|
28 | SLEEP=/bin/sleep
|
---|
29 | else
|
---|
30 | SLEEP=/usr/bin/sleep
|
---|
31 | fi
|
---|
32 |
|
---|
33 | write_or_exit() {
|
---|
34 | # make has been killed or failed or run to completion, leave
|
---|
35 | [[ ! -e /proc/${MAKE_PPID} ]] && echo -n "${CURSOR_ON}" && exit
|
---|
36 |
|
---|
37 | # Target build complete, leave.
|
---|
38 | [[ -f ${TARGET} ]] && echo -n "${CURSOR_ON}" && exit
|
---|
39 |
|
---|
40 | # It is safe to write to the screen
|
---|
41 | echo -n "$1"
|
---|
42 | }
|
---|
43 |
|
---|
44 | # initialize screen
|
---|
45 | write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec"
|
---|
46 |
|
---|
47 | # loop forever..
|
---|
48 | while true ; do
|
---|
49 |
|
---|
50 | # Loop through the animation string
|
---|
51 | for GRAPHIC_CHAR in ${GRAPHIC_STR} ; do
|
---|
52 | write_or_exit "${CSI}$((SEC + 3))G${GRAPHIC_CHAR}"
|
---|
53 | $SLEEP .12 # This value MUST be less than .2 seconds.
|
---|
54 | done
|
---|
55 |
|
---|
56 | # A BASH internal variable, the number of seconds the script
|
---|
57 | # has been running. modulo convert to 0-59
|
---|
58 | SEC=$((SECONDS % 60))
|
---|
59 |
|
---|
60 | # Detect rollover of the seconds.
|
---|
61 | (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}"
|
---|
62 | PREV_SEC=$SEC
|
---|
63 |
|
---|
64 | # Display the accumulated time. div minutes.. modulo seconds.
|
---|
65 | write_or_exit "${TS_POSITION}$((SECONDS / 60)) min. $SEC sec"
|
---|
66 | done
|
---|
67 |
|
---|
68 | exit
|
---|