From 7696f58ea4b3892cf264a6b89df1a44c4cafe738 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 3 Jun 2018 13:14:17 +1000 Subject: [PATCH] uptime: Remove subshells --- neofetch | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/neofetch b/neofetch index 6fb0d16f..0e9e0163 100755 --- a/neofetch +++ b/neofetch @@ -1197,18 +1197,15 @@ get_uptime() { hours="$((seconds / 60 / 60 % 24)) hours" mins="$((seconds / 60 % 60)) minutes" - # Format the days, hours and minutes. - strip_date() { - case "$1" in - "0 "*) unset "${1/* }" ;; - "1 "*) printf "%s" "${1/s}" ;; - *) printf "%s" "$1" ;; - esac - } + # Remove plural if < 2. + ((${days/ *} == 1)) && days="${days/s}" + ((${hours/ *} == 1)) && hours="${hours/s}" + ((${mins/ *} == 1)) && mins="${mins/s}" - days="$(strip_date "$days")" - hours="$(strip_date "$hours")" - mins="$(strip_date "$mins")" + # Hide empty fields. + ((${days/ *} == 0)) && unset days + ((${hours/ *} == 0)) && unset hours + ((${mins/ *} == 0)) && unset mins uptime="${days:+$days, }${hours:+$hours, }${mins}" uptime="${uptime%', '}"