From 83e2df7f310a1292472f6f2d75a19f287a8924d4 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Sep 2019 08:07:42 +0300 Subject: [PATCH] memort: macos support --- pfetch | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/pfetch b/pfetch index cac0652..ba3e553 100755 --- a/pfetch +++ b/pfetch @@ -302,10 +302,30 @@ get_memory() { mem_full=$((mem_full / 1024)) ;; + # Used memory is calculated using the following "formula" (MacOS): + # wired + active + occupied * 4 / 1024 Darwin*) - # If you run macOS and can send me the full output of - # 'vm_stat' I'll be able to add full support here. mem_full=$(($(sysctl -n hw.memsize) / 1024 / 1024)) + + # Parse the 'vmstat' file splitting on ':' and '.'. + # The format of the file is 'key: 000.' and an additional + # split is used on '.' to filter it out. + while IFS=:. read -r key val; do + case $key in + *wired*|*active*|*occupied*) + mem_used=$((mem_used + ${val:-0})) + ;; + esac + + # Using '<<-EOF' is the only way to loop over a command's + # output without the use of a pipe ('|') or subshell. + # This ensures that any variables defined in the while loop + # are still accessible in the script. + done <<-EOF + $(vmstat) + EOF + + mem_used=$((mem_used * 4 / 1024)) ;; OpenBSD*) @@ -714,6 +734,11 @@ get_ascii() { while read -r line; do ascii_height=$((ascii_height + 1)) ascii_width=$((${#line} > ascii_width ? ${#line} : ascii_width)) + + # Using '<<-EOF' is the only way to loop over a command's + # output without the use of a pipe ('|') or subshell. + # This ensures that any variables defined in the while loop + # are still accessible in the script. done <<-EOF $(printf %s "$ascii" | sed 's/\[3.m//g') EOF @@ -758,6 +783,8 @@ main() { $(uname -sr) EOF + os=Darwin + # Always run 'get_os' for the purposes of detecting which ascii # art to display. get_os