Ignore:
Timestamp:
04/13/2019 04:33:38 PM (5 years ago)
Author:
Pierre Labastie <pierre@…>
Branches:
ablfs-more, legacy, trunk
Children:
c048987
Parents:
0e4ddfa
Message:

Improve common/progress_bar.sh based on shellcheck:

  • remove useless array declarations
  • remove unused variables
  • remove $ prefix for variable names in arithmetic expressions
  • normalize indentation (2 spaces)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/progress_bar.sh

    r0e4ddfa rbc2f591  
    1 
     1# shellcheck shell=bash
    22# $Id$
    33
     
    1616declare -r  FRAME_CLOSE=${CSI}$'63G]'
    1717declare -r  TS_POSITION=${CSI}$'65G'
    18 declare -r  LINE_WRAP_OFF=${CSI}$'?7l'
    19 declare -r  LINE_WRAP_ON=${CSI}$'?7h'
    20 declare -a  RESET_LINE=${CURSOR_OFF}${ERASE_LINE}${FRAME_OPEN}${FRAME_CLOSE}
     18declare -r  RESET_LINE=${CURSOR_OFF}${ERASE_LINE}${FRAME_OPEN}${FRAME_CLOSE}
    2119
    22 declare -a  GRAPHIC_STR="| / - \\ + "
     20declare -r  GRAPHIC_STR="| / - \\ + "
    2321declare -i  SEC=0  # Seconds accumulator
    2422declare -i  PREV_SEC=0
     
    5048while true ; do
    5149
    52       # Loop through the animation string
    53     for GRAPHIC_CHAR in ${GRAPHIC_STR} ; do
    54       write_or_exit "${CSI}$((SEC + 3))G${GRAPHIC_CHAR}"
    55       $SLEEP .12 # This value MUST be less than .2 seconds.
    56     done
     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
    5755
    58       # A BASH internal variable, the number of seconds the script
    59       # has been running. modulo convert to 0-59
    60     SEC=$(($SECONDS % 60))
     56    # A BASH internal variable, the number of seconds the script
     57    # has been running. modulo convert to 0-59
     58  SEC=$((SECONDS % 60))
    6159
    62       # Detect rollover of the seconds.
    63     (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}"
    64     PREV_SEC=$SEC
     60    # Detect rollover of the seconds.
     61  (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}"
     62  PREV_SEC=$SEC
    6563
    66       # Display the accumulated time. div minutes.. modulo seconds.
    67     write_or_exit "${TS_POSITION}$(($SECONDS / 60)) min. $SEC sec"
     64    # Display the accumulated time. div minutes.. modulo seconds.
     65  write_or_exit "${TS_POSITION}$((SECONDS / 60)) min. $SEC sec"
    6866done
    6967
Note: See TracChangeset for help on using the changeset viewer.