summaryrefslogtreecommitdiff
path: root/.local/bin/blocks/memory
blob: c581a53a1d296669e9b349045c568f6fca5b4133 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash

LABEL=${LABEL:"+"}
TYPE="${TYPE:-mem}"

awk -v type=$TYPE '
/^MemTotal:/ {
	mem_total=$2
}
/^MemFree:/ {
	mem_free=$2
}
/^Buffers:/ {
	mem_free+=$2
}
/^Cached:/ {
	mem_free+=$2
}
END {
	free=mem_free/1024/1024
	used=(mem_total-mem_free)/1024/1024
	total=mem_total/1024/1024

	pct=0
	if (total > 0) {
		pct=used/total*100
	}

	# Full text.
	# printf("%s %.1fG/%.1fG (%.f%%)\n", LABEL, used, total, pct)
	printf("%s %.1fG\n", LABEL, used)
	# Short text.
	printf("%s %.f%%\n", LABEL, pct)

	# Color.
	if (pct > 90) {
		print("#FF0000")
	} else if (pct > 80) {
		print("#FFAE00")
	} else if (pct > 70) {
		print("#FFF600")
	}
}
' /proc/meminfo