From 13135b698e1683662d71c962b4087600920bf1fc Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 5 Dec 2016 10:30:01 +1100 Subject: [PATCH 1/3] Memory: [FreeBSD] Rewrite memory functon --- neofetch | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/neofetch b/neofetch index b2c8e4e7..0c29e8f3 100755 --- a/neofetch +++ b/neofetch @@ -1074,21 +1074,30 @@ get_memory() { ;; "BSD") + # Mem total case "$distro" in - "NetBSD"*) - memfree="$(($(awk -F ':|kB' '/MemFree:/ {printf $2}' /proc/meminfo) / 1024))" - mem_total="$(($(sysctl -n hw.physmem64) / 1024 / 1024))" - ;; - - *) - memfree="$(($(vmstat | awk 'END{printf $5}') / 1024))" - mem_total="$(($(sysctl -n hw.physmem) / 1024 / 1024))" - ;; + "NetBSD"*) mem_total="$(($(sysctl -n hw.physmem64) / 1024 / 1024))" ;; + *) mem_total="$(($(sysctl -n hw.physmem) / 1024 / 1024))" ;; esac + # Mem free case "$distro" in - "OpenBSD"*) mem_used="$(($(vmstat | awk 'END {printf $4}') / 1024))" ;; - *) mem_used="$((mem_total - memfree))" ;; + "NetBSD"*) mem_free="$(($(awk -F ':|kB' '/MemFree:/ {printf $2}' /proc/meminfo) / 1024))" ;; + "FreeBSD"* | "DragonFly"*) + mem_info=($(sysctl -n hw.pagesize bm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count)) + mem_inactive="$((mem_info[1] * meminfo[0]))" + mem_cache="$((mem_info[2] * meminfo[0]))" + mem_free="$((mem_info[3] * meminfo[0]))" + mem_free="$((mem_inactive + mem_cache + mem_free))" + ;; + "OpenBSD"*) ;; + *) mem_free="$(($(vmstat | awk 'END{printf $5}') / 1024))" ;; + esac + + # Mem used + case "$distro" in + "OpenBSD"*) mem_used="$(($(vmstat | awk 'END{printf $4}') / 1024))" ;; + *) mem_used="$((mem_total - mem_free))" ;; esac ;; From 4c860aaea47b035452b0bc9a87073ded6c2f637a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 5 Dec 2016 10:51:00 +1100 Subject: [PATCH 2/3] Memory: [FreeBSD] Fix memory usage --- neofetch | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/neofetch b/neofetch index 0c29e8f3..3cae7094 100755 --- a/neofetch +++ b/neofetch @@ -1083,13 +1083,7 @@ get_memory() { # Mem free case "$distro" in "NetBSD"*) mem_free="$(($(awk -F ':|kB' '/MemFree:/ {printf $2}' /proc/meminfo) / 1024))" ;; - "FreeBSD"* | "DragonFly"*) - mem_info=($(sysctl -n hw.pagesize bm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count)) - mem_inactive="$((mem_info[1] * meminfo[0]))" - mem_cache="$((mem_info[2] * meminfo[0]))" - mem_free="$((mem_info[3] * meminfo[0]))" - mem_free="$((mem_inactive + mem_cache + mem_free))" - ;; + "FreeBSD"* | "DragonFly"*) mem_free="$(top -d 1 | awk -F ',' '/^Mem:/ {print $5}')";; "OpenBSD"*) ;; *) mem_free="$(($(vmstat | awk 'END{printf $5}') / 1024))" ;; esac From 242b2bd58958e4e5a6bcf39be11110f5d4019e4d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 5 Dec 2016 10:55:56 +1100 Subject: [PATCH 3/3] Memory: [BSD] Remove Free from output --- neofetch | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 3cae7094..bfd80a6e 100755 --- a/neofetch +++ b/neofetch @@ -1083,7 +1083,11 @@ get_memory() { # Mem free case "$distro" in "NetBSD"*) mem_free="$(($(awk -F ':|kB' '/MemFree:/ {printf $2}' /proc/meminfo) / 1024))" ;; - "FreeBSD"* | "DragonFly"*) mem_free="$(top -d 1 | awk -F ',' '/^Mem:/ {print $5}')";; + "FreeBSD"* | "DragonFly"*) + mem_free="$(top -d 1 | awk -F ',' '/^Mem:/ {print $5}')" + mem_free="${mem_free/M Free}" + ;; + "OpenBSD"*) ;; *) mem_free="$(($(vmstat | awk 'END{printf $5}') / 1024))" ;; esac