memory: simplify

This commit is contained in:
Dylan Araps 2018-04-15 20:17:01 +10:00
parent d7172fa89b
commit 4212e83fe0
1 changed files with 12 additions and 4 deletions

View File

@ -1432,12 +1432,20 @@ get_gpu() {
get_memory() {
case "$os" in
"Linux" | "Windows")
IFS=$'\n'":kB" read -d "" -ra mem < /proc/meminfo
# MemUsed = Memtotal + Shmem - MemFree - Buffers - Cached - SReclaimable
# Source: https://github.com/KittyKatt/screenFetch/issues/386#issuecomment-249312716
mem_used="$(((mem[1] + mem[64] - mem[4] - mem[11] - mem[14]- mem[70]) / 1024))"
mem_total="$((mem[1] / 1024))"
while IFS=":" read -r a b; do
case "$a" in
"MemTotal") mem_used="$((mem_used+=${b/kB}))"; mem_total="${b/kB}" ;;
"Shmem") mem_used="$((mem_used+=${b/kB}))" ;;
"MemFree" | "Buffers" | "Cached" | "SReclaimable")
mem_used="$((mem_used-=${b/kB}))"
;;
esac
done < /proc/meminfo
mem_used="$((mem_used / 1024))"
mem_total="$((mem_total / 1024))"
;;
"Mac OS X" | "iPhone OS")