1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # $Id$
|
---|
4 |
|
---|
5 | set -e
|
---|
6 |
|
---|
7 | # Be sure that we know the taget name
|
---|
8 | [[ -z $1 ]] && exit
|
---|
9 | TARGET=$1 # Remember the target build we are looking for
|
---|
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 -a RESET_LINE=${CURSOR_OFF}${ERASE_LINE}${FRAME_OPEN}${FRAME_CLOSE}
|
---|
19 |
|
---|
20 | declare -a GRAPHIC_STR="| / - \\ + "
|
---|
21 | declare -i SEC=0 # Seconds accumulator
|
---|
22 | declare -i PREV_SEC=0
|
---|
23 |
|
---|
24 | mypid=$$
|
---|
25 | # A small ugly.. who is my parent *not root
|
---|
26 | makePID=`(cat /proc/$mypid/stat) | cut -d " " -f5`
|
---|
27 |
|
---|
28 | write_or_exit() {
|
---|
29 | # make has been killed or failed or run to completion, leave
|
---|
30 | [[ ! -e /proc/$makePID ]] && echo -n "${CURSOR_ON}" && exit
|
---|
31 |
|
---|
32 | # Target build complete, leave.
|
---|
33 | [[ -f ${TARGET} ]] && echo -n "${CURSOR_ON}" && exit
|
---|
34 |
|
---|
35 | # It is safe to write to the screen
|
---|
36 | echo -n "$1"
|
---|
37 | }
|
---|
38 |
|
---|
39 | # initialize screen
|
---|
40 | write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec. "
|
---|
41 |
|
---|
42 | # loop forever..
|
---|
43 | while true ; do
|
---|
44 |
|
---|
45 | # Loop through the animation string
|
---|
46 | for GRAPHIC_CHAR in ${GRAPHIC_STR} ; do
|
---|
47 | write_or_exit "${CSI}$((SEC + 3))G${GRAPHIC_CHAR}"
|
---|
48 | sleep .12 # This value MUST be less than .2 seconds.
|
---|
49 | done
|
---|
50 |
|
---|
51 | # A BASH internal variable, the number of seconds the script
|
---|
52 | # has been running. modulo convert to 0-59
|
---|
53 | SEC=$(($SECONDS % 60))
|
---|
54 |
|
---|
55 | # Detect rollover of the seconds.
|
---|
56 | (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}"
|
---|
57 | (( PREV_SEC = SEC ))
|
---|
58 |
|
---|
59 | # Display the accumulated time. div minutes.. modulo seconds.
|
---|
60 | write_or_exit "${TS_POSITION}$(($SECONDS / 60)) min. $SEC sec. "
|
---|
61 | done
|
---|
62 |
|
---|
63 | exit
|
---|