From 6e29174b0948e497d0cc58e7da9ce8ed4f11c0db Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Tue, 9 Feb 2021 21:56:30 -0500 Subject: Show battery level while charging, time while discharging Also fix initial sleep calculation when seconds has a leading zero, and limit the length of time left for when it initially says "unknown". --- home/.local/bin/clock | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'home') diff --git a/home/.local/bin/clock b/home/.local/bin/clock index 8f30ea8e..704b4040 100755 --- a/home/.local/bin/clock +++ b/home/.local/bin/clock @@ -2,9 +2,14 @@ set -eu tput civis -sleep=$(( 60 - $(date +'%S') )) +sleep=$(( 60 - $(date +'%S' | sed 's/^0//') )) while :; do - printf '%3sm %s' "$(apm -m)" "$(date +'%a %H:%M')" + if [ $(apm -a) -eq 1 ]; then + printf '%3s%%' "$(apm -l)" + else + printf '%3.3sm' "$(apm -m)" + fi + printf ' %s\r' "$(date +'%a %H:%M')" sleep $sleep sleep=60 done -- cgit 1.4.1