From 92487fba8b2906c821d2821f9e8abfa606c11c6e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 24 Sep 2019 20:35:03 +0300 Subject: [PATCH] pfetch: better macOS/BSD support --- pfetch | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pfetch b/pfetch index 5f2cf25..3215779 100755 --- a/pfetch +++ b/pfetch @@ -115,9 +115,15 @@ get_os() { . /etc/os-release && distro=$PRETTY_NAME ;; + Darwin*) + # TODO: Parse '/System/Library/CoreServices/SystemVersion.plist' + # to grab the full distribution name, version and build. + distro=macOS + ;; + *) # Catch all to ensure '$distro' is never blank. - # This should also handle the BSDs, macOS etc. + # This also handles the BSDs. distro="$os $kernel" ;; esac @@ -161,6 +167,19 @@ get_uptime() { Linux*) IFS=. read -r s _ < /proc/uptime ;; + + Darwin*|BSD*) + s=$(sysctl kern.boottime) + + # Extract the uptime in seconds from the following output: + # [...] { sec = 1271934886, usec = 667779 } Thu Apr 22 12:14:46 2010 + s=${s#*=} + s=${s%,*} + + # The uptime format from 'sysctl' needs to be subtracted from + # the current time in seconds. + s="$(($(date +%s) - s))" + ;; esac # Convert the uptime from seconds into days, hours and minutes. @@ -354,7 +373,7 @@ get_ascii() { EOF ;; - [Mm]ac[Oo][Ss]*) + [Mm]ac[Oo][Ss]*|[Dd]arwin*) read_ascii 1 <<-EOF ${c1} .:' _ :'_