source: common/progress_bar.sh@ 26e1214

experimental
Last change on this file since 26e1214 was 3b63c8c, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Updated experimental branch to current trunk code.

  • Property mode set to 100755
File size: 1.7 KB
RevLine 
[460ea63]1#!/bin/bash
2
3# $Id$
4
5set -e
6
[9199a13]7# Be sure that we know the taget name
[460ea63]8[[ -z $1 ]] && exit
[9199a13]9TARGET=$1 # Remember the target build we are looking for
[460ea63]10
[9199a13]11declare -r CSI=$'\e[' # DEC terminology, Control Sequence Introducer
12declare -r CURSOR_OFF=${CSI}$'?25l'
13declare -r CURSOR_ON=${CSI}$'?25h'
14declare -r ERASE_LINE=${CSI}$'2K'
15declare -r FRAME_OPEN=${CSI}$'2G['
16declare -r FRAME_CLOSE=${CSI}$'63G]'
17declare -r TS_POSITION=${CSI}$'65G'
18declare -a RESET_LINE=${CURSOR_OFF}${ERASE_LINE}${FRAME_OPEN}${FRAME_CLOSE}
19
20declare -a GRAPHIC_STR="| / - \\ + "
21declare -i SEC=0 # Seconds accumulator
22declare -i PREV_SEC=0
23
[3b63c8c]24makePID=$(fuser -v . 2>&1 | grep make)
25makePID=$(echo $makePID | cut -d" " -f2)
[9199a13]26
27write_or_exit() {
28 # make has been killed or failed or run to completion, leave
[3b63c8c]29 [[ ! -e /proc/$makePID ]] && echo -n "${CURSOR_ON}" && exit
30
[9199a13]31 # Target build complete, leave.
32 [[ -f ${TARGET} ]] && echo -n "${CURSOR_ON}" && exit
[3b63c8c]33
[9199a13]34 # It is safe to write to the screen
35 echo -n "$1"
36}
37
38 # initialize screen
39write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec. "
40
41 # loop forever..
42while true ; do
43
44 # Loop through the animation string
45 for GRAPHIC_CHAR in ${GRAPHIC_STR} ; do
46 write_or_exit "${CSI}$((SEC + 3))G${GRAPHIC_CHAR}"
47 sleep .12 # This value MUST be less than .2 seconds.
48 done
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. "
60done
61
62exit
Note: See TracBrowser for help on using the repository browser.