aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpfetch22
1 files changed, 21 insertions, 1 deletions
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() {