Merge pull request #383 from konimex/uptime-fix
Solaris: Rewritten uptime
This commit is contained in:
commit
86cfc366c2
1 changed files with 37 additions and 40 deletions
77
neofetch
77
neofetch
|
@ -268,55 +268,52 @@ getkernel() {
|
||||||
# Uptime {{{
|
# Uptime {{{
|
||||||
|
|
||||||
getuptime() {
|
getuptime() {
|
||||||
|
# Get uptime in seconds
|
||||||
case "$os" in
|
case "$os" in
|
||||||
"Linux" | "Windows" | "Mac OS X" | "iPhone OS" | "BSD")
|
"Linux" | "Windows")
|
||||||
# Get uptime in seconds
|
seconds="$(< /proc/uptime)"
|
||||||
case "$os" in
|
seconds="${seconds/.*}"
|
||||||
"Linux" | "Windows")
|
;;
|
||||||
seconds="$(< /proc/uptime)"
|
|
||||||
seconds="${seconds/.*}"
|
|
||||||
;;
|
|
||||||
|
|
||||||
"Mac OS X" | "iPhone OS" | "BSD")
|
"Mac OS X" | "iPhone OS" | "BSD")
|
||||||
boot="$(sysctl -n kern.boottime)"
|
boot="$(sysctl -n kern.boottime)"
|
||||||
boot="${boot/'{ sec = '}"
|
boot="${boot/'{ sec = '}"
|
||||||
boot="${boot/,*}"
|
boot="${boot/,*}"
|
||||||
|
|
||||||
# Get current date in seconds
|
# Get current date in seconds
|
||||||
now="$(date +%s)"
|
now="$(date +%s)"
|
||||||
seconds="$((now - boot))"
|
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}"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"Solaris")
|
"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
|
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.
|
# Make the output of uptime smaller.
|
||||||
case "$uptime_shorthand" in
|
case "$uptime_shorthand" in
|
||||||
"on")
|
"on")
|
||||||
|
|
Loading…
Reference in a new issue