Improve display of uptime

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-06-25 16:25:31 +02:00
parent 90b4caa724
commit b2ac615dfb
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5

View file

@ -1,3 +1,22 @@
#!/usr/bin/env zsh
printf "\uf2f2 %.1fd\n" $(($(cut -d ' ' -f 1 </proc/uptime) / 86400.0))
up_secs=$(cut -d ' ' -f 1 </proc/uptime | cut -d . -f 1)
num=0
suffix=d
if [ $up_secs -gt 86400 ]; then
num=$((up_secs / 86400.0))
suffix=d
elif [ $up_secs -gt 3600 ]; then
num=$((up_secs / 3600.0))
suffix=h
elif [ $up_secs -gt 60 ]; then
num=$((up_secs / 60.0))
suffix=m
else
num=${up_secs}
suffix=s
fi
printf "\uf2f2 %.0f%s\n" ${num} ${suffix}