Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRD WebDesign <github@rdwebdesign.com.br>2022-07-25 02:15:20 +0300
committerRD WebDesign <github@rdwebdesign.com.br>2022-07-25 02:15:20 +0300
commitd89720330f7434254c52f094d1117f67aaa8cf1a (patch)
tree4db3547b47479605bb834149e0feefa9b0f9f676
parent8d1f286f30d4415dac2f1efff38bb32491f26904 (diff)
Address revision requests:fix/spinner
- replace `local var` with `_var` (POSIX style); - move inline comments Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
-rwxr-xr-xadvanced/Scripts/piholeDebug.sh39
1 files changed, 23 insertions, 16 deletions
diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh
index 34348885..1707b872 100755
--- a/advanced/Scripts/piholeDebug.sh
+++ b/advanced/Scripts/piholeDebug.sh
@@ -1346,34 +1346,41 @@ check_database_integrity() {
}
# Show a text spinner during a long process run
-#
spinner(){
# Show the spinner only if there is a tty
if tty -s; then
- local PID=$! # PID of the most recent background process
- local spin="/-\|"
- local start=0
- local elapsed=0
- local i=1
+ # PID of the most recent background process
+ _PID=$!
+ _spin="/-\|"
+ _start=0
+ _elapsed=0
+ _i=1
+
+ # Start the counter
+ _start=$(date +%s)
- start=$(date +%s) # Start the counter
+ # Hide the cursor
+ tput civis > /dev/tty
- tput civis > /dev/tty # Hide the cursor
- trap 'tput cnorm > /dev/tty' EXIT # ensures cursor is visible again, in case of premature exit
+ # ensures cursor is visible again, in case of premature exit
+ trap 'tput cnorm > /dev/tty' EXIT
- while [ -d /proc/$PID ]; do
- elapsed=$(( $(date +%s) - start ))
+ while [ -d /proc/$_PID ]; do
+ _elapsed=$(( $(date +%s) - _start ))
# use hours only if needed
- if [ "$elapsed" -lt 3600 ]; then
- printf "\r${spin:i++%${#spin}:1} %02d:%02d" $((elapsed/60)) $((elapsed%60)) >"$(tty)"
+ if [ "$_elapsed" -lt 3600 ]; then
+ printf "\r${_spin:_i++%${#_spin}:1} %02d:%02d" $((_elapsed/60)) $((_elapsed%60)) >"$(tty)"
else
- printf "\r${spin:i++%${#spin}:1} %02d:%02d:%02d" $((elapsed/3600)) $(((elapsed/60)%60)) $((elapsed%60)) >"$(tty)"
+ printf "\r${_spin:_i++%${#_spin}:1} %02d:%02d:%02d" $((_elapsed/3600)) $(((_elapsed/60)%60)) $((_elapsed%60)) >"$(tty)"
fi
sleep 0.25
done
- printf "\r" >"$(tty)" # Return to the begin of the line after completion (the spinner will be overwritten)
- tput cnorm > /dev/tty # Restore cursor visibility
+ # Return to the begin of the line after completion (the spinner will be overwritten)
+ printf "\r" >"$(tty)"
+
+ # Restore cursor visibility
+ tput cnorm > /dev/tty
fi
}