Changeset 9199a13 for common/progress_bar.sh
- Timestamp:
- 06/10/2006 04:48:25 PM (18 years ago)
- Branches:
- experimental
- Children:
- 966cb20
- Parents:
- e35e794
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/progress_bar.sh
re35e794 r9199a13 5 5 set -e 6 6 7 # Be sure that we know the taget name 7 8 [[ -z $1 ]] && exit 9 TARGET=$1 # Remember the target build we are looking for 8 10 9 if [ ! -f $1 ] ; then 10 while fuser -v . 2>&1 | grep make >/dev/null ; do 11 echo -n "." 12 sleep 1 13 [[ -f $1 ]] && exit 14 done 15 fi 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 25 write_or_exit() { 26 # make has been killed or failed or run to completion, leave 27 if ! fuser -v . 2>&1 | grep make >/dev/null ; then 28 echo -n "${CURSOR_ON}" && exit 29 fi 30 # Target build complete, leave. 31 [[ -f ${TARGET} ]] && echo -n "${CURSOR_ON}" && exit 32 # It is safe to write to the screen 33 echo -n "$1" 34 } 35 36 # initialize screen 37 write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec. " 38 39 # loop forever.. 40 while true ; do 41 42 # Loop through the animation string 43 for GRAPHIC_CHAR in ${GRAPHIC_STR} ; do 44 write_or_exit "${CSI}$((SEC + 3))G${GRAPHIC_CHAR}" 45 sleep .12 # This value MUST be less than .2 seconds. 46 done 47 48 # A BASH internal variable, the number of seconds the script 49 # has been running. modulo convert to 0-59 50 SEC=$(($SECONDS % 60)) 51 52 # Detect rollover of the seconds. 53 (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}" 54 (( PREV_SEC = SEC )) 55 56 # Display the accumulated time. div minutes.. modulo seconds. 57 write_or_exit "${TS_POSITION}$(($SECONDS / 60)) min. $SEC sec. " 58 done 59 60 exit
Note:
See TracChangeset
for help on using the changeset viewer.