From 707bd74cf86cd91111e6191e30e8d12e1dc349bf Mon Sep 17 00:00:00 2001 From: davidovski Date: Thu, 2 Feb 2023 10:42:59 +0000 Subject: Fix hbar with no arguments --- src/util/hbar.sh | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/util/hbar.sh b/src/util/hbar.sh index 603f66a..502bdc1 100755 --- a/src/util/hbar.sh +++ b/src/util/hbar.sh @@ -3,12 +3,12 @@ . /usr/lib/xilib.sh move_up () { - [ ! "$1" = "-1" ] && + [ ! "$1" = "0" ] && printf "\033[%dA" "$1" "0" } move_down () { - [ ! "$1" = "-1" ] && + [ ! "$1" = "0" ] && printf "\033[%dB" "$1" } @@ -21,7 +21,7 @@ count_string () { c=$1 t=$2 } - printf "[%s%s/%s%s]" $c $unit $t $unit + printf "[%s/%s]" $c $t } hbar () { @@ -58,11 +58,11 @@ hbar () { ;; esac done + shift $((OPTIND-1)) [ "$#" -lt 2 ] && { - printf "$RESET\n" - exit 1 + return 1 } completed="$1" @@ -71,7 +71,7 @@ hbar () { move_up $line count=$(count_string $completed $total) - printf "\r$text" + #printf "\r$text" printf "$RESET\r" printf "$color" @@ -86,16 +86,27 @@ hbar () { printf "%s" "${text%%${text#?}}" text="${text#?}" } || { - printf " " + [ "$((width-${#count}))" = "$i" ] && { + printf "%s" "${count%%${count#?}}" + count="${count#?}" + } || { + printf " " + } } i=$((i+1)) done move_down $line - $terminate && printf "$RESET\n" + printf "$RESET" + $terminate && printf "\n" exit 0 } -printf "%s" "$(hbar "$@")" +[ "$#" -eq "0" ] && { + printf "$RESET\n" + exit 0 +} + +printf "$(hbar "$@")" -- cgit v1.2.1