From 0dbfb77bad56417eedc9372ca03bccbbe62b3ab1 Mon Sep 17 00:00:00 2001 From: Crestwave <35413013+Crestwave@users.noreply.github.com> Date: Thu, 3 Oct 2019 10:19:55 +0800 Subject: [PATCH] neofetch: fix uptime (#4207) --- app-misc/neofetch/neofetch-6.1.0.recipe | 2 +- .../neofetch/patches/neofetch-6.1.0.patchset | 137 ++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) diff --git a/app-misc/neofetch/neofetch-6.1.0.recipe b/app-misc/neofetch/neofetch-6.1.0.recipe index d3923d050..1ebe2a949 100644 --- a/app-misc/neofetch/neofetch-6.1.0.recipe +++ b/app-misc/neofetch/neofetch-6.1.0.recipe @@ -16,7 +16,7 @@ ARCHITECTURES="any" USER_SETTINGS_FILES="$relativeSettingsDir/neofetch/config.conf" PROVIDES=" - neofetch + neofetch = $portVersion cmd:neofetch " REQUIRES=" diff --git a/app-misc/neofetch/patches/neofetch-6.1.0.patchset b/app-misc/neofetch/patches/neofetch-6.1.0.patchset index 559fff81d..bcb92feb1 100644 --- a/app-misc/neofetch/patches/neofetch-6.1.0.patchset +++ b/app-misc/neofetch/patches/neofetch-6.1.0.patchset @@ -29,3 +29,140 @@ index 1a68247..6bb7118 100755 -- 2.23.0 +From ed5d136193a93d3270aa630eb74db7c3ec304610 Mon Sep 17 00:00:00 2001 +From: Crestwave +Date: Sat, 28 Sep 2019 09:02:13 +0000 +Subject: [PATCH] Fix uptime + +--- + neofetch | 103 ++++++++++++++++++++++++++----------------------------- + 1 file changed, 48 insertions(+), 55 deletions(-) + +diff --git a/neofetch b/neofetch +index 1a68247..ab23c79 100755 +--- a/neofetch ++++ b/neofetch +@@ -1213,72 +1213,65 @@ get_kernel() { + } + + get_uptime() { +- # Since Haiku's uptime cannot be fetched in seconds, a case outside +- # the usual case is needed. ++ # Get uptime in seconds. + case "$os" in +- "Haiku") +- uptime="$(uptime -u)" +- uptime="${uptime/up }" ++ "Linux" | "Windows" | "MINIX") ++ if [[ -r /proc/uptime ]]; then ++ seconds="$(< /proc/uptime)" ++ seconds="${seconds/.*}" ++ else ++ boot="$(date -d"$(uptime -s)" +%s)" ++ now="$(date +%s)" ++ seconds="$((now - boot))" ++ fi + ;; + +- *) +- # Get uptime in seconds. +- case "$os" in +- "Linux" | "Windows" | "MINIX") +- 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") ++ boot="$(sysctl -n kern.boottime)" ++ boot="${boot/\{ sec = }" ++ boot="${boot/,*}" + +- "Mac OS X" | "iPhone OS" | "BSD" | "FreeMiNT") +- boot="$(sysctl -n kern.boottime)" +- boot="${boot/\{ sec = }" +- boot="${boot/,*}" ++ # Get current date in seconds. ++ now="$(date +%s)" ++ seconds="$((now - boot))" ++ ;; + +- # Get current date in seconds. +- now="$(date +%s)" +- seconds="$((now - boot))" +- ;; ++ "Solaris") ++ seconds="$(kstat -p unix:0:system_misc:snaptime | awk '{print $2}')" ++ seconds="${seconds/.*}" ++ ;; + +- "Solaris") +- seconds="$(kstat -p unix:0:system_misc:snaptime | awk '{print $2}')" +- seconds="${seconds/.*}" +- ;; ++ "AIX" | "IRIX") ++ t="$(LC_ALL=POSIX ps -o etime= -p 1)" ++ 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") +- t="$(LC_ALL=POSIX ps -o etime= -p 1)" +- 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 ++ "Haiku") ++ seconds=$(($(system_time) / 1000000)) ++ ;; ++ esac + +- days="$((seconds / 60 / 60 / 24)) days" +- hours="$((seconds / 60 / 60 % 24)) hours" +- mins="$((seconds / 60 % 60)) minutes" ++ 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}" ++ # 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 ++ # 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 ++ uptime="${days:+$days, }${hours:+$hours, }${mins}" ++ uptime="${uptime%', '}" ++ uptime="${uptime:-${seconds} seconds}" + + # Make the output of uptime smaller. + case "$uptime_shorthand" in +-- +2.23.0 +