This commit is contained in:
2023-04-12 20:32:07 +02:00
committed by soraefir
parent 10fbbc2654
commit a7ef5cf996
96 changed files with 5857 additions and 4 deletions

14
home/gui/eww/scripts/memory Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
total="$(free --si | rg Mem | awk '{print $2}')"
human() {
awk -v mem="$1" 'BEGIN{print sprintf("%.1f%s", mem/1000/(mem > 1000000 ? 1000 : 1), mem > 1000000 ? "G" : "M")}'
}
free --si -s 3 | rg --line-buffered Mem | while read -r line; do
used=$(echo "$line" | awk '{print $3}')
perc=$(awk -v used="$used" -v total="$total" 'BEGIN{print sprintf("%.f", used/total*100)}')
echo '{"total": "'$(human "$total")'", "used": "'$(human "$used")'", "percent": '$perc'}'
done