Skip to content

Commit

Permalink
plugins: Improve progress plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Oct 3, 2024
1 parent 3be06a8 commit 184da07
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 28 deletions.
4 changes: 2 additions & 2 deletions plugins/progress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Bash. The function handles printing of the progress bar.
2. **Invoke `progress` Function:**
- Within a shell function, call the `progress` function whenever you want to display the progress bar.
- Pass two parameters to the `progress` function:
- `PARAM_PROGRESS`: The progress percentage (0-100) of the task.
- `PARAM_STATUS`: Optional. A status message to display alongside the progress bar.
- `value`: The progress percentage (0-100) of the task. Passing 0 will reset the progress bar status.
- `message`: Optional. A status message to display alongside the progress bar.

```bash
# Example usage:
Expand Down
79 changes: 53 additions & 26 deletions plugins/progress/progress.plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

################################################################################

# Global variable to store progress value
_omb_plugin_progress_value=0

#
# Description : delay executing script
Expand All @@ -29,32 +31,57 @@ function delay()
#
# Description : print out executing progress
#
CURRENT_PROGRESS=0
function progress()
{
PARAM_PROGRESS=$1;
PARAM_STATUS=$2;

if [ $CURRENT_PROGRESS -le 0 -a $PARAM_PROGRESS -ge 0 ] ; then echo -ne "[..........................] (0%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 5 -a $PARAM_PROGRESS -ge 5 ] ; then echo -ne "[#.........................] (5%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 10 -a $PARAM_PROGRESS -ge 10 ]; then echo -ne "[##........................] (10%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 15 -a $PARAM_PROGRESS -ge 15 ]; then echo -ne "[###.......................] (15%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 20 -a $PARAM_PROGRESS -ge 20 ]; then echo -ne "[####......................] (20%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 25 -a $PARAM_PROGRESS -ge 25 ]; then echo -ne "[#####.....................] (25%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 30 -a $PARAM_PROGRESS -ge 30 ]; then echo -ne "[######....................] (30%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 35 -a $PARAM_PROGRESS -ge 35 ]; then echo -ne "[#######...................] (35%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 40 -a $PARAM_PROGRESS -ge 40 ]; then echo -ne "[########..................] (40%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 45 -a $PARAM_PROGRESS -ge 45 ]; then echo -ne "[#########.................] (45%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 50 -a $PARAM_PROGRESS -ge 50 ]; then echo -ne "[##########................] (50%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 55 -a $PARAM_PROGRESS -ge 55 ]; then echo -ne "[###########...............] (55%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 60 -a $PARAM_PROGRESS -ge 60 ]; then echo -ne "[############..............] (60%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 65 -a $PARAM_PROGRESS -ge 65 ]; then echo -ne "[#############.............] (65%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 70 -a $PARAM_PROGRESS -ge 70 ]; then echo -ne "[###############...........] (70%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 75 -a $PARAM_PROGRESS -ge 75 ]; then echo -ne "[#################.........] (75%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 80 -a $PARAM_PROGRESS -ge 80 ]; then echo -ne "[####################......] (80%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 85 -a $PARAM_PROGRESS -ge 85 ]; then echo -ne "[#######################...] (90%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 90 -a $PARAM_PROGRESS -ge 90 ]; then echo -ne "[##########################] (100%) $PARAM_PHASE \r" ; delay; fi;
if [ $CURRENT_PROGRESS -le 100 -a $PARAM_PROGRESS -ge 100 ];then echo -ne 'Done! \n' ; delay; fi;

CURRENT_PROGRESS=$PARAM_PROGRESS;
local value=$1;
local message=$2;

if [ -z $value ]; then
printf "Usage: progress <value> [message]\n\n"
printf "Options:\n"
printf " value The value for the progress bar. Use 0 to reset.\n"
printf " message The optional message to display next to the progress bar.\n"
return 0
fi

if [ $value -lt 0 ]; then
_omb_log_error "invalid value: value' (expect: 0-100)" >&2
return 2
fi

# Reset the progress value
if [ $value -eq 0 ]; then
_omb_plugin_progress_value=0;
return 0
fi

# Clear the message whitespace
local size=40-${#message}
local whitespace=""
for ((i=0; i<size; i++)); do
whitespace="$whitespace "
done

if [ $_omb_plugin_progress_value -le 0 -a $value -ge 0 ] ; then echo -ne "[--------------------------] (0%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 5 -a $value -ge 5 ] ; then echo -ne "[#-------------------------] (5%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 10 -a $value -ge 10 ]; then echo -ne "[##------------------------] (10%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 15 -a $value -ge 15 ]; then echo -ne "[###-----------------------] (15%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 20 -a $value -ge 20 ]; then echo -ne "[####----------------------] (20%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 25 -a $value -ge 25 ]; then echo -ne "[#####---------------------] (25%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 30 -a $value -ge 30 ]; then echo -ne "[######--------------------] (30%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 35 -a $value -ge 35 ]; then echo -ne "[#######-------------------] (35%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 40 -a $value -ge 40 ]; then echo -ne "[########------------------] (40%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 45 -a $value -ge 45 ]; then echo -ne "[#########-----------------] (45%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 50 -a $value -ge 50 ]; then echo -ne "[##########----------------] (50%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 55 -a $value -ge 55 ]; then echo -ne "[###########---------------] (55%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 60 -a $value -ge 60 ]; then echo -ne "[############--------------] (60%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 65 -a $value -ge 65 ]; then echo -ne "[#############-------------] (65%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 70 -a $value -ge 70 ]; then echo -ne "[###############-----------] (70%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 75 -a $value -ge 75 ]; then echo -ne "[#################---------] (75%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 80 -a $value -ge 80 ]; then echo -ne "[####################------] (80%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 85 -a $value -ge 85 ]; then echo -ne "[#######################---] (90%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 90 -a $value -ge 90 ]; then echo -ne "[##########################] (100%) $message$whitespace \r" ; delay; fi;
if [ $_omb_plugin_progress_value -le 100 -a $value -ge 100 ];then echo -ne 'Done! \n' ; delay; fi;

_omb_plugin_progress_value=$value;
}

0 comments on commit 184da07

Please sign in to comment.