uptime: [haiku] Fix uptime

This commit is contained in:
Dylan Araps 2019-09-26 09:50:02 +03:00
parent 15153f78d7
commit a0a7f3ec54

107
neofetch
View file

@ -1213,73 +1213,66 @@ get_kernel() {
} }
get_uptime() { get_uptime() {
# Since Haiku's uptime cannot be fetched in seconds, a case outside # Get uptime in seconds.
# the usual case is needed.
case "$os" in case "$os" in
"Haiku") "Linux" | "Windows" | "MINIX")
uptime="$(uptime -u)" if [[ -r /proc/uptime ]]; then
uptime="${uptime/up }" seconds="$(< /proc/uptime)"
seconds="${seconds/.*}"
else
boot="$(date -d"$(uptime -s)" +%s)"
now="$(date +%s)"
seconds="$((now - boot))"
fi
;; ;;
*) "Mac OS X" | "iPhone OS" | "BSD" | "FreeMiNT")
# Get uptime in seconds. boot="$(sysctl -n kern.boottime)"
case "$os" in boot="${boot/\{ sec = }"
"Linux" | "Windows" | "MINIX") boot="${boot/,*}"
if [[ -r /proc/uptime ]]; then
seconds="$(< /proc/uptime)"
seconds="${seconds/.*}"
else
boot="$(date -d"$(uptime -s)" +%s)"
now="$(date +%s)"
seconds="$((now - boot))"
fi
;;
"Mac OS X" | "iPhone OS" | "BSD" | "FreeMiNT") # Get current date in seconds.
boot="$(sysctl -n kern.boottime)" now="$(date +%s)"
boot="${boot/\{ sec = }" seconds="$((now - boot))"
boot="${boot/,*}" ;;
# Get current date in seconds. "Solaris")
now="$(date +%s)" seconds="$(kstat -p unix:0:system_misc:snaptime | awk '{print $2}')"
seconds="$((now - boot))" seconds="${seconds/.*}"
;; ;;
"Solaris") "AIX" | "IRIX")
seconds="$(kstat -p unix:0:system_misc:snaptime | awk '{print $2}')" t="$(LC_ALL=POSIX ps -o etime= -p 1)"
seconds="${seconds/.*}" d="0" h="0"
;; case "$t" in *"-"*) d="${t%%-*}"; t="${t#*-}";; esac
case "$t" in *":"*":"*) h="${t%%:*}"; t="${t#*:}";; esac
h="${h#0}" t="${t#0}"
seconds="$((d*86400 + h*3600 + ${t%%:*}*60 + ${t#*:}))"
;;
"AIX" | "IRIX") "Haiku")
t="$(LC_ALL=POSIX ps -o etime= -p 1)" seconds=$(($(system_time) / 1000000))
d="0" h="0"
case "$t" in *"-"*) d="${t%%-*}"; t="${t#*-}";; esac
case "$t" in *":"*":"*) h="${t%%:*}"; t="${t#*:}";; esac
h="${h#0}" t="${t#0}"
seconds="$((d*86400 + h*3600 + ${t%%:*}*60 + ${t#*:}))"
;;
esac
days="$((seconds / 60 / 60 / 24)) days"
hours="$((seconds / 60 / 60 % 24)) hours"
mins="$((seconds / 60 % 60)) minutes"
# Remove plural if < 2.
((${days/ *} == 1)) && days="${days/s}"
((${hours/ *} == 1)) && hours="${hours/s}"
((${mins/ *} == 1)) && mins="${mins/s}"
# Hide empty fields.
((${days/ *} == 0)) && unset days
((${hours/ *} == 0)) && unset hours
((${mins/ *} == 0)) && unset mins
uptime="${days:+$days, }${hours:+$hours, }${mins}"
uptime="${uptime%', '}"
uptime="${uptime:-${seconds} seconds}"
;; ;;
esac esac
days="$((seconds / 60 / 60 / 24)) days"
hours="$((seconds / 60 / 60 % 24)) hours"
mins="$((seconds / 60 % 60)) minutes"
# Remove plural if < 2.
((${days/ *} == 1)) && days="${days/s}"
((${hours/ *} == 1)) && hours="${hours/s}"
((${mins/ *} == 1)) && mins="${mins/s}"
# Hide empty fields.
((${days/ *} == 0)) && unset days
((${hours/ *} == 0)) && unset hours
((${mins/ *} == 0)) && unset mins
uptime="${days:+$days, }${hours:+$hours, }${mins}"
uptime="${uptime%', '}"
uptime="${uptime:-${seconds} seconds}"
# Make the output of uptime smaller. # Make the output of uptime smaller.
case "$uptime_shorthand" in case "$uptime_shorthand" in
"on") "on")