From e4c7f1926acc525a411385124e172eec8e7e004d Mon Sep 17 00:00:00 2001 From: Muhammad Herdiansyah Date: Fri, 21 Oct 2016 16:06:51 +0700 Subject: [PATCH] Solaris: Rewritten uptime Solaris' uptime will now show the second mark only so we don't have 2 case instances. --- neofetch | 77 +++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/neofetch b/neofetch index 94f3b4c3..3cdefc07 100755 --- a/neofetch +++ b/neofetch @@ -268,55 +268,52 @@ getkernel() { # Uptime {{{ getuptime() { + # Get uptime in seconds case "$os" in - "Linux" | "Windows" | "Mac OS X" | "iPhone OS" | "BSD") - # Get uptime in seconds - case "$os" in - "Linux" | "Windows") - seconds="$(< /proc/uptime)" - seconds="${seconds/.*}" - ;; + "Linux" | "Windows") + seconds="$(< /proc/uptime)" + seconds="${seconds/.*}" + ;; - "Mac OS X" | "iPhone OS" | "BSD") - boot="$(sysctl -n kern.boottime)" - boot="${boot/'{ sec = '}" - boot="${boot/,*}" + "Mac OS X" | "iPhone OS" | "BSD") + boot="$(sysctl -n kern.boottime)" + boot="${boot/'{ sec = '}" + boot="${boot/,*}" - # Get current date in seconds - now="$(date +%s)" - seconds="$((now - boot))" - ;; - esac - - days="$((seconds / 60 / 60 / 24)) days" - hours="$((seconds / 60 / 60 % 24)) hours" - minutes="$((seconds / 60 % 60)) minutes" - - case "$days" in - "0 days") unset days ;; - "1 days") days="${days/s}" ;; - esac - - case "$hours" in - "0 hours") unset hours ;; - "1 hours") hours="${hours/s}" ;; - esac - - case "$minutes" in - "0 minutes") unset minutes ;; - "1 minutes") minutes="${minutes/s}" ;; - esac - - uptime="${days:+$days, }${hours:+$hours, }${minutes}" - uptime="${uptime%', '}" - uptime="up ${uptime:-${seconds} seconds}" + # Get current date in seconds + now="$(date +%s)" + seconds="$((now - boot))" ;; "Solaris") - uptime="$(uptime | /usr/xpg4/bin/awk -F ':[0-9]{2}+[a-z][a-z] |(, ){1}+' '{printf $2}')" + seconds="$(kstat -p unix:0:system_misc:snaptime | awk '{print $2}')" + seconds="${seconds/.*}" ;; esac + days="$((seconds / 60 / 60 / 24)) days" + hours="$((seconds / 60 / 60 % 24)) hours" + minutes="$((seconds / 60 % 60)) minutes" + + case "$days" in + "0 days") unset days ;; + "1 days") days="${days/s}" ;; + esac + + case "$hours" in + "0 hours") unset hours ;; + "1 hours") hours="${hours/s}" ;; + esac + + case "$minutes" in + "0 minutes") unset minutes ;; + "1 minutes") minutes="${minutes/s}" ;; + esac + + uptime="${days:+$days, }${hours:+$hours, }${minutes}" + uptime="${uptime%', '}" + uptime="up ${uptime:-${seconds} seconds}" + # Make the output of uptime smaller. case "$uptime_shorthand" in "on")