From 262906b6c1202c95e3f3dd962ce75642b416dae1 Mon Sep 17 00:00:00 2001 From: Connor Sheridan Date: Thu, 25 Mar 2021 17:24:23 -0400 Subject: [PATCH] Fixing butchered formatting --- usr/lib/byobu/memory | 136 +++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/usr/lib/byobu/memory b/usr/lib/byobu/memory index fd24b445..50b0dbaa 100755 --- a/usr/lib/byobu/memory +++ b/usr/lib/byobu/memory @@ -20,78 +20,78 @@ # along with this program. If not, see . __memory_detail() { - free + free } __memory() { - local free="" total="" buffers="" cached="" - local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0 + local free="" total="" buffers="" cached="" + local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0 - if [ $(uname) = "Linux" ]; then - if [ -r /proc/meminfo ]; then - while read tok val unit; do - case "$tok" in - MemTotal:) total=${val};; - MemFree:) free=${val};; - Buffers:) buffers=${val};; - Cached:) cached=${val};; - esac - [ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break; - done < /proc/meminfo - fi - elif [ $(uname) = "FreeBSD" ]; then - # FreeBSD support - mem_phys=$(sysctl -n hw.physmem) - page_size=$(sysctl -n hw.pagesize) - mem_inactive=$(($(sysctl -n vm.stats.vm.v_inactive_count)*$page_size)) - mem_cache=$(($(sysctl -n vm.stats.vm.v_cache_count)*$page_size)) - mem_free=$(($(sysctl -n vm.stats.vm.v_free_count)*$page_size)) - - mem_avail=$(($mem_inactive+$mem_cache+$mem_free)) - mem_used=$(($mem_phys-$mem_avail)) - - total=$(($mem_phys/1024)) - free=$(($mem_avail/1024)) - - buffers=0 - cached=0 - elif eval $BYOBU_TEST vm_stat >/dev/null 2>&1; then - # MacOS support - # calculation borrowed from http://apple.stackexchange.com/a/48195/18857 - free_blocks=$(vm_stat | grep free | awk '{ print $3 }' | sed -e 's/\.//') - inactive_blocks=$(vm_stat | grep inactive | awk '{ print $3 }' | sed -e 's/\.//') - speculative_blocks=$(vm_stat | grep speculative | awk '{ print $3 }' | sed -e 's/\.//') - free=$((($free_blocks+speculative_blocks)*4)) - inactive=$(($inactive_blocks*4)) - total=$(($free+$inactive)) - buffers=0 - cached=0 + if [ $(uname) = "Linux" ]; then + if [ -r /proc/meminfo ]; then + while read tok val unit; do + case "$tok" in + MemTotal:) total=${val};; + MemFree:) free=${val};; + Buffers:) buffers=${val};; + Cached:) cached=${val};; + esac + [ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break; + done < /proc/meminfo fi + elif [ $(uname) = "FreeBSD" ]; then + # FreeBSD support + mem_phys=$(sysctl -n hw.physmem) + page_size=$(sysctl -n hw.pagesize) + mem_inactive=$(($(sysctl -n vm.stats.vm.v_inactive_count)*$page_size)) + mem_cache=$(($(sysctl -n vm.stats.vm.v_cache_count)*$page_size)) + mem_free=$(($(sysctl -n vm.stats.vm.v_free_count)*$page_size)) - kb_main_used=$(($total-$free)) - buffers_plus_cached=$(($buffers+$cached)) - # "free output" buffers and cache (output from 'free') - fo_buffers=$(($kb_main_used - $buffers_plus_cached)) - fpdiv $((100*${fo_buffers})) "${total}" 0; - usage=${_RET} + mem_avail=$(($mem_inactive+$mem_cache+$mem_free)) + mem_used=$(($mem_phys-$mem_avail)) - if [ $total -ge 1048576 ]; then - fpdiv "$total" 1048567 1 - total=${_RET} - unit="$ICON_GB" - elif [ $total -ge 1024 ]; then - fpdiv "$total" 1024 0 - total=${_RET} - unit="$ICON_MB" - else - unit="$ICON_KB" - fi - if [ $usage -gt 90 ]; then - # Change foreground to yellow, if usage over 90% - fg="Y" - else - fg="W" - fi - [ -n "$total" ] || return - color b g W; printf "%s" "$total"; color -; color g W; printf "%s" "$unit"; color -; color b g "$fg"; printf "%s" "$usage"; color -; color g "$fg"; printf "%s" "$PCT"; color -- -} \ No newline at end of file + total=$(($mem_phys/1024)) + free=$(($mem_avail/1024)) + + buffers=0 + cached=0 + elif eval $BYOBU_TEST vm_stat >/dev/null 2>&1; then + # MacOS support + # calculation borrowed from http://apple.stackexchange.com/a/48195/18857 + free_blocks=$(vm_stat | grep free | awk '{ print $3 }' | sed -e 's/\.//') + inactive_blocks=$(vm_stat | grep inactive | awk '{ print $3 }' | sed -e 's/\.//') + speculative_blocks=$(vm_stat | grep speculative | awk '{ print $3 }' | sed -e 's/\.//') + free=$((($free_blocks+speculative_blocks)*4)) + inactive=$(($inactive_blocks*4)) + total=$(($free+$inactive)) + buffers=0 + cached=0 + fi + + kb_main_used=$(($total-$free)) + buffers_plus_cached=$(($buffers+$cached)) + # "free output" buffers and cache (output from 'free') + fo_buffers=$(($kb_main_used - $buffers_plus_cached)) + fpdiv $((100*${fo_buffers})) "${total}" 0; + usage=${_RET} + + if [ $total -ge 1048576 ]; then + fpdiv "$total" 1048567 1 + total=${_RET} + unit="$ICON_GB" + elif [ $total -ge 1024 ]; then + fpdiv "$total" 1024 0 + total=${_RET} + unit="$ICON_MB" + else + unit="$ICON_KB" + fi + if [ $usage -gt 90 ]; then + # Change foreground to yellow, if usage over 90% + fg="Y" + else + fg="W" + fi + [ -n "$total" ] || return + color b g W; printf "%s" "$total"; color -; color g W; printf "%s" "$unit"; color -; color b g "$fg"; printf "%s" "$usage"; color -; color g "$fg"; printf "%s" "$PCT"; color -- +}