aboutsummaryrefslogtreecommitdiffstats
path: root/.config/init/helpers
diff options
context:
space:
mode:
authorkatherine <shmibs@airen-no-jikken.icu>2018-12-21 17:26:56 -0700
committerkatherine <shmibs@airen-no-jikken.icu>2018-12-21 17:26:56 -0700
commitcda3ce7be62bd74452a10d8a83055a7969b171db (patch)
treea477e2c18949cdff1ed0fcfaf86ea2b55f527c15 /.config/init/helpers
parent8612af96ca914867c5d539e31d5cd7a2dc0a2a98 (diff)
downloaddotfiles-cda3ce7be62bd74452a10d8a83055a7969b171db.tar.gz
add time elapsed to progress-bar
Diffstat (limited to '.config/init/helpers')
-rw-r--r--.config/init/helpers23
1 files changed, 14 insertions, 9 deletions
diff --git a/.config/init/helpers b/.config/init/helpers
index 1f2ed89..81859ec 100644
--- a/.config/init/helpers
+++ b/.config/init/helpers
@@ -55,21 +55,22 @@ progress-bar() {
local i=0
local starttime=$EPOCHREALTIME
local lasttime=$starttime
- local thistime=$starttime
+ local thistime=$starttime
local elapsed=0
while true; do
+ local now=$EPOCHREALTIME
[[ $i -eq $count ]] && break
local width=$COLUMNS
- local statwidth=$(( ($#count * 2) + 20))
+ local statwidth=$(( ($#count * 2) + 35))
local progwidth=$(($width - $statwidth - 3))
[[ $progwidth -gt 30 || $progwidth -le 1 ]] && progwidth=30
- if [[ $i -eq 0 || $elapsed -eq 0 ]]; then
+ if [[ $i -eq 0 ]]; then
eta='??:??:??'
else
- local left=$(( ($count - $i) * ($elapsed / $i) - ($EPOCHREALTIME - $lasttime) ))
+ local left=$(( ($count - $i) * ($elapsed / $i) - ($now - $lasttime) ))
if [[ $left -ge 86400 ]]; then
eta=' days...'
elif [[ $left -le 0 ]]; then
@@ -79,21 +80,25 @@ progress-bar() {
fi
fi
+ local rt=$(($now - $starttime))
+ [[ $rt -ge 86400 ]] && rt=' days...' \
+ || rt=$(strftime '%H:%M:%S' ${$(( floor($rt + 802800) )):s/\./})
+
local fpart=""
local epart=""
local progress=$(($i * $progwidth / $count))
repeat $progress fpart="$fpart#"
- repeat $(($progwidth-$progress)) epart="$epart-"
+ repeat $(($progwidth - $progress)) epart="$epart-"
printf \
- "\e[G\e[K$colour%s...\e[0m\n[%${#count}s/$count] [eta: $eta] [$fpart$epart]\e[J" \
+ "\e[G\e[K$colour%s...\e[0m\n[%${#count}s/$count] [rt: $rt] [eta: $eta] [$fpart$epart]\e[J" \
$message \
$i \
read -t 0.2 \
- && thistime=$EPOCHREALTIME \
- && elapsed=$(($elapsed + $thistime - $lasttime)) \
- && lasttime=$EPOCHREALTIME \
+ && thistime=$EPOCHREALTIME \
+ && elapsed=$(($elapsed - $lasttime + $thistime)) \
+ && lasttime=$thistime \
&& i=$(($i + 1))
printf "\e[F"