mirror of
https://github.com/The-Repo-Club/DotFiles.git
synced 2025-01-31 01:24:24 -05:00
49 lines
1.2 KiB
Bash
Executable File
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
|