2020-07-23 16:47:18 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-10-17 00:38:29 +02:00
|
|
|
# setting the locale, some users have issues with different locales, this forces the correct one
|
|
|
|
export LC_ALL=en_US.UTF-8
|
2020-06-04 05:44:17 +02:00
|
|
|
|
2021-10-10 01:48:10 +02:00
|
|
|
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
source $current_dir/utils.sh
|
2020-08-10 13:57:48 +02:00
|
|
|
|
2023-01-07 23:58:58 +01:00
|
|
|
get_ratio()
|
2020-06-04 05:44:17 +02:00
|
|
|
{
|
2021-07-06 10:22:36 +02:00
|
|
|
case $(uname -s) in
|
|
|
|
Linux)
|
2023-01-07 18:36:14 +01:00
|
|
|
usage="$(free -h | awk 'NR==2 {print $3}')"
|
|
|
|
total="$(free -h | awk 'NR==2 {print $2}')"
|
|
|
|
formated="${usage}/${total}"
|
|
|
|
|
|
|
|
echo "${formated//i/B}"
|
2021-07-06 10:22:36 +02:00
|
|
|
;;
|
2020-06-04 05:44:17 +02:00
|
|
|
|
2021-07-06 10:22:36 +02:00
|
|
|
Darwin)
|
2021-08-10 21:56:52 +02:00
|
|
|
# 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}')
|
2023-12-15 16:57:07 +01:00
|
|
|
# System Profiler performs an activation lock check, which can result in
|
|
|
|
# time outs or a lagged response. (~10 seconds)
|
|
|
|
# total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}')
|
|
|
|
total_mem=$(sysctl -n hw.memsize | awk '{print $0/1024/1024/1024 " GB"}')
|
2023-01-07 23:58:58 +01:00
|
|
|
if ((used_mem < 1024 )); then
|
|
|
|
echo "${used_mem}MB/$total_mem"
|
2021-07-06 10:22:36 +02:00
|
|
|
else
|
2023-01-07 23:58:58 +01:00
|
|
|
memory=$((used_mem/1024))
|
|
|
|
echo "${memory}GB/$total_mem"
|
2021-07-06 10:22:36 +02:00
|
|
|
fi
|
|
|
|
;;
|
2020-09-02 03:24:39 +02:00
|
|
|
|
2021-07-06 10:22:36 +02:00
|
|
|
FreeBSD)
|
|
|
|
# Looked at the code from neofetch
|
|
|
|
hw_pagesize="$(sysctl -n hw.pagesize)"
|
|
|
|
mem_inactive="$(($(sysctl -n vm.stats.vm.v_inactive_count) * hw_pagesize))"
|
|
|
|
mem_unused="$(($(sysctl -n vm.stats.vm.v_free_count) * hw_pagesize))"
|
|
|
|
mem_cache="$(($(sysctl -n vm.stats.vm.v_cache_count) * hw_pagesize))"
|
2020-06-04 05:44:17 +02:00
|
|
|
|
2021-07-06 10:22:36 +02:00
|
|
|
free_mem=$(((mem_inactive + mem_unused + mem_cache) / 1024 / 1024))
|
|
|
|
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
|
|
|
|
used_mem=$((total_mem - free_mem))
|
|
|
|
echo $used_mem
|
2023-01-07 23:58:58 +01:00
|
|
|
if ((used_mem < 1024 )); then
|
|
|
|
echo "${used_mem}MB/$total_mem"
|
2021-07-06 10:22:36 +02:00
|
|
|
else
|
2023-01-07 23:58:58 +01:00
|
|
|
memory=$((used_mem/1024))
|
|
|
|
echo "${memory}GB/$total_mem"
|
2021-07-06 10:22:36 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2023-02-10 18:25:03 +01:00
|
|
|
OpenBSD)
|
|
|
|
# vmstat -s | grep "pages managed" | sed -ne 's/^ *\([0-9]*\).*$/\1/p'
|
|
|
|
# Looked at the code from neofetch
|
|
|
|
hw_pagesize="$(pagesize)"
|
2023-02-14 18:56:36 +01:00
|
|
|
used_mem=$(( (
|
|
|
|
$(vmstat -s | grep "pages active$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
|
|
|
|
$(vmstat -s | grep "pages inactive$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
|
|
|
|
$(vmstat -s | grep "pages wired$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
|
|
|
|
$(vmstat -s | grep "pages zeroed$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
|
|
|
|
0) * hw_pagesize / 1024 / 1024 ))
|
2023-02-10 18:25:03 +01:00
|
|
|
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
|
2023-02-14 18:56:36 +01:00
|
|
|
#used_mem=$((total_mem - free_mem))
|
2023-02-10 18:25:03 +01:00
|
|
|
total_mem=$(($total_mem/1024))
|
|
|
|
if (( $used_mem < 1024 )); then
|
|
|
|
echo $used_mem\M\B/$total_mem\G\B
|
|
|
|
else
|
|
|
|
memory=$(($used_mem/1024))
|
|
|
|
echo $memory\G\B/$total_mem\G\B
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2021-07-06 10:22:36 +02:00
|
|
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
|
|
|
# TODO - windows compatability
|
|
|
|
;;
|
|
|
|
esac
|
2020-06-04 05:44:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
2023-12-21 03:32:56 +01:00
|
|
|
ram_label=$(get_tmux_option "@kanagawa-ram-usage-label" "RAM")
|
2023-01-07 23:58:58 +01:00
|
|
|
ram_ratio=$(get_ratio)
|
|
|
|
echo "$ram_label $ram_ratio"
|
2020-06-04 05:44:17 +02:00
|
|
|
}
|
2020-06-04 06:33:47 +02:00
|
|
|
|
2020-06-04 05:44:17 +02:00
|
|
|
#run main driver
|
|
|
|
main
|