Skip to content

Commit

Permalink
on Linux (or similar) use free(1) to get RAM (close #542)
Browse files Browse the repository at this point in the history
  • Loading branch information
darealshinji authored Jun 2, 2018
1 parent ead8bd8 commit c499205
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions screenfetch-dev
Original file line number Diff line number Diff line change
Expand Up @@ -1655,17 +1655,20 @@ detectmem () {
else
# MemUsed = Memtotal + Shmem - MemFree - Buffers - Cached - SReclaimable
# Source: https://github.com/dylanaraps/neofetch/pull/391/files#diff-e863270127ca6116fd30e708cdc582fc
mem_info=$(</proc/meminfo)
mem_info=$(echo $(echo $(mem_info=${mem_info// /}; echo ${mem_info//kB/})))
for m in $mem_info; do
case ${m//:*} in
"MemTotal") usedmem=$((usedmem+=${m//*:})); totalmem=${m//*:} ;;
"Shmem") usedmem=$((usedmem+=${m//*:})) ;;
"MemFree"|"Buffers"|"Cached"|"SReclaimable") usedmem=$((usedmem-=${m//*:})) ;;
esac
done
usedmem=$((usedmem / 1024))
totalmem=$((totalmem / 1024))
#mem_info=$(</proc/meminfo)
#mem_info=$(echo $(echo $(mem_info=${mem_info// /}; echo ${mem_info//kB/})))
#for m in $mem_info; do
# case ${m//:*} in
# "MemTotal") usedmem=$((usedmem+=${m//*:})); totalmem=${m//*:} ;;
# "Shmem") usedmem=$((usedmem+=${m//*:})) ;;
# "MemFree"|"Buffers"|"Cached"|"SReclaimable") usedmem=$((usedmem-=${m//*:})) ;;
# esac
#done
#usedmem=$((usedmem / 1024))
#totalmem=$((totalmem / 1024))
mem=$(free -b | awk 'NR==2{print $2"-"$7}')
usedmem=$((mem / 1024 / 1024))
totalmem=$((${mem//-*} / 1024 / 1024))
fi
mem="${usedmem}MiB / ${totalmem}MiB"
verboseOut "Finding current RAM usage...found as '$mem'"
Expand Down

0 comments on commit c499205

Please sign in to comment.