From 223de3d82afd00381522e05d9c46b5daf4cef9a0 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Sep 2019 17:41:38 +0300 Subject: [PATCH] memory: freebsd support --- pfetch | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/pfetch b/pfetch index 71d1908..c21f030 100755 --- a/pfetch +++ b/pfetch @@ -212,7 +212,7 @@ get_host() { host="$name $version $model" ;; - Darwin*) + Darwin*|FreeBSD*) host=$(sysctl -n hw.model) ;; @@ -401,8 +401,6 @@ get_memory() { ;; OpenBSD*) - # 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 @@ -426,10 +424,31 @@ get_memory() { EOF ;; + # Used memory is calculated using the following "formula" (FreeBSD): + # (inactive_count + free_count + cache_count) * page_size / 1024 FreeBSD*) - # If you run FreeBSD and can help me get - # the used memory amount, I'll be able to add support here. mem_full=$(($(sysctl -n hw.physmem) / 1024 / 1024)) + + # Use 'set --' to store the output of the command in the + # argument list. POSIX sh has no arrays but this is close enough. + # + # Disable the shellcheck warning for word-splitting + # as it's safe and intended ('set -f' disables globbing). + # shellcheck disable=2046 + { + set -f + set +f -- $(sysctl -n hw.pagesize \ + vm.stats.vm.v_inactive_count \ + vm.stats.vm.v_free_count \ + vm.stats.vm.v_cache_count) + } + + # Calculate the amount of free memory. + # $1: hw.pagesize + # $2: vm.stats.vm.v_inactive_count + # $3: vm.stats.vm.v_free_count + # $4: vm.stats.vm.v_cache_count + mem_free=$((($2 + $3 + $4) * $1 / 1024 / 1024)) ;; NetBSD*)