From 856cabf75763996fd1965ef067fcebaef72b7309 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 15 Dec 2016 22:55:15 +1100 Subject: [PATCH] Uptime: Rewrite part of uptime --- config/config | 4 ++-- neofetch | 28 +++++++++++++--------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/config/config b/config/config index 53b809b5..9384d597 100644 --- a/config/config +++ b/config/config @@ -92,7 +92,7 @@ os_arch="on" # Shorten the output of the uptime function # -# Default: 'off' +# Default: 'on' # Values: 'on', 'off', 'tiny' # Flag: --uptime_shorthand # @@ -100,7 +100,7 @@ os_arch="on" # on: '2 days, 10 hours, 3 mins' # off: '2 days, 10 hours, 3 minutes' # tiny: '2d 10h 3m' -uptime_shorthand="off" +uptime_shorthand="on" # Shell diff --git a/neofetch b/neofetch index 2f88963e..03dfc20f 100755 --- a/neofetch +++ b/neofetch @@ -329,24 +329,22 @@ get_uptime() { days="$((seconds / 60 / 60 / 24)) days" hours="$((seconds / 60 / 60 % 24)) hours" - minutes="$((seconds / 60 % 60)) minutes" + mins="$((seconds / 60 % 60)) minutes" - case "$days" in - "0 days") unset days ;; - "1 days") days="${days/s}" ;; - esac + # Format the days, hours and minutes. + strip_date() { + case "$1" in + "0 "*) unset "${1/* }" ;; + "1 "*) printf "%s" "${1/s}" ;; + *) printf "%s" "$1" ;; + esac + } - case "$hours" in - "0 hours") unset hours ;; - "1 hours") hours="${hours/s}" ;; - esac + days="$(strip_date "$days")" + hours="$(strip_date "$hours")" + mins="$(strip_date "$mins")" - case "$minutes" in - "0 minutes") unset minutes ;; - "1 minutes") minutes="${minutes/s}" ;; - esac - - uptime="${days:+$days, }${hours:+$hours, }${minutes}" + uptime="${days:+$days, }${hours:+$hours, }${mins}" uptime="${uptime%', '}" uptime="${uptime:-${seconds} seconds}" ;;