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