From f4e9f3b4cae78cebdc076ddb9b55e07162e709d8 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Sep 2019 15:43:39 +0300 Subject: [PATCH] memory: openbsd memory detection --- pfetch | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pfetch b/pfetch index 87f9d13..8fbfd74 100755 --- a/pfetch +++ b/pfetch @@ -393,6 +393,26 @@ get_memory() { # If you run OpenBSD and can send me the full output of # 'vm_stat' I'll be able to add full support here. mem_full=$(($(sysctl -n hw.physmem) / 1024 / 1024)) + + # This is a really simpler parser for 'vmstat' which grabs + # the used memory amount in a lazy way. 'vmstat' prints 3 + # lines of output with the needed value being stored in the + # third and last line. + # + # This loop simply grabs the 3rd element of each line until + # the EOF is reached. Each line overwrites the value of the + # previous so we're left with what we wanted. This isn't + # slow as only 3 lines are parsed! + while read -r _ _ line _; do + mem_used=${line%%M} + + # Using '<<-EOF' is the only way to loop over a command's + # output without the use of a pipe ('|'). + # This ensures that any variables defined in the while loop + # are still accessible in the script. + done <<-EOF + $(vmstat) + EOF ;; FreeBSD*) @@ -419,7 +439,7 @@ get_memory() { ;; esac - log memory "${mem_used:-?}MiB / ${mem_full:-?}MiB" >&6 + log memory "${mem_used:-?}M / ${mem_full:-?}M" >&6 } get_ascii() {