TheRepoClub-DotFiles/lemonbar/.local/bin/lemonbar/lemonbar_ram
2021-12-31 05:21:12 +00:00

49 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
ram() {
icon=" "
memory_unit="gib"
while IFS=":" read -r a b; do
case $a in
"MemTotal") ((mem_used+=${b/kB})); mem_total="${b/kB}" ;;
"Shmem") ((mem_used+=${b/kB})) ;;
"MemFree" | "Buffers" | "Cached" | "SReclaimable")
mem_used="$((mem_used-=${b/kB}))"
;;
"MemAvailable")
mem_avail=${b/kB}
;;
esac
done < /proc/meminfo
if [[ $mem_avail ]]; then
mem_used=$(((mem_total - mem_avail) / 1024))
else
mem_used="$((mem_used / 1024))"
fi
mem_total="$((mem_total / 1024))"
case $memory_unit in
gib)
mem_used=$(awk '{printf "%.2f", $1 / $2}' <<< "$mem_used 1024")
mem_total=$(awk '{printf "%.2f", $1 / $2}' <<< "$mem_total 1024")
mem_label=GiB
;;
kib)
mem_used=$((mem_used * 1024))
mem_total=$((mem_total * 1024))
mem_label=KiB
;;
esac
memory="${mem_used}${mem_label:-MiB} / ${mem_total}${mem_label:-MiB} ${mem_perc:+(${mem_perc}%)}"
printf "%s%s\n" "%{F#1e222a}%{B#AC8476}$icon %{F-}%{B-}" "%{F#1e222a}%{B#C4C7C5} $memory %{F-}%{B-}"
}
ram