From 1d3d07c3d251e6f70524934f7eab8273a58456f4 Mon Sep 17 00:00:00 2001 From: Adrien Kara Date: Sat, 7 Jan 2023 23:58:58 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(ram=5Finfo):=20cl?= =?UTF-8?q?eanup=20and=20follow=20bash=20recommendations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove the sleep rate, controled by show_refresh in dracula.sh Signed-off-by: Adrien Kara --- scripts/ram_info.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index ab983d5..00af64a 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -5,7 +5,7 @@ export LC_ALL=en_US.UTF-8 current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $current_dir/utils.sh -get_percent() +get_ratio() { case $(uname -s) in Linux) @@ -20,11 +20,11 @@ get_percent() # Get used memory blocks with vm_stat, multiply by page size to get size in bytes, then convert to MiB used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk -v pagesize=$(pagesize) '{printf "%d\n", ($1+$2) * pagesize / 1048576}') total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}') - if (( $used_mem < 1024 )); then - echo $used_mem\M\B/$total_mem + if ((used_mem < 1024 )); then + echo "${used_mem}MB/$total_mem" else - memory=$(($used_mem/1024)) - echo $memory\G\B/$total_mem + memory=$((used_mem/1024)) + echo "${memory}GB/$total_mem" fi ;; @@ -39,11 +39,11 @@ get_percent() total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024)) used_mem=$((total_mem - free_mem)) echo $used_mem - if (( $used_mem < 1024 )); then - echo $used_mem\M\B/$total_mem + if ((used_mem < 1024 )); then + echo "${used_mem}MB/$total_mem" else - memory=$(($used_mem/1024)) - echo $memory\G\B/$total_mem + memory=$((used_mem/1024)) + echo "${memory}GB/$total_mem" fi ;; @@ -55,12 +55,9 @@ get_percent() main() { - # storing the refresh rate in the variable RATE, default is 5 - RATE=$(get_tmux_option "@dracula-refresh-rate" 5) ram_label=$(get_tmux_option "@dracula-ram-usage-label" "RAM") - ram_percent=$(get_percent) - echo "$ram_label $ram_percent" - sleep $RATE + ram_ratio=$(get_ratio) + echo "$ram_label $ram_ratio" } #run main driver