Fixes the uptime status notification on OS X.

This commit is contained in:
Kevin Mark 2016-05-28 10:05:27 -04:00
commit 757ba0fbdc

View file

@ -30,6 +30,12 @@ __uptime() {
if [ -r /proc/uptime ]; then if [ -r /proc/uptime ]; then
read u idle < /proc/uptime read u idle < /proc/uptime
u=${u%.*} u=${u%.*}
elif [ -x /usr/sbin/sysctl ]; then
u=$(/usr/sbin/sysctl -n kern.boottime | cut -f4 -d' ' | cut -d',' -f1)
u=$(($(date +%s) - $u))
fi
if [ "$u" ]; then
if [ "$u" -gt 86400 ]; then if [ "$u" -gt 86400 ]; then
str="$(($u / 86400))d$((($u % 86400) / 3600))h" str="$(($u / 86400))d$((($u % 86400) / 3600))h"
elif [ "$u" -gt 3600 ]; then elif [ "$u" -gt 3600 ]; then
@ -42,6 +48,7 @@ __uptime() {
else else
str=$(uptime | sed -e "s/.* up *//" -e "s/ *days, */d/" -e "s/:/h/" -e "s/,.*/m/") str=$(uptime | sed -e "s/.* up *//" -e "s/ *days, */d/" -e "s/:/h/" -e "s/,.*/m/")
fi fi
[ -n "$str" ] || return [ -n "$str" ] || return
color w b; printf "%s" "${str}"; color -- color w b; printf "%s" "${str}"; color --
} }