aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'dot_config/i3/scripts/executable_memory')
-rw-r--r--dot_config/i3/scripts/executable_memory69
1 files changed, 69 insertions, 0 deletions
diff --git a/dot_config/i3/scripts/executable_memory b/dot_config/i3/scripts/executable_memory
new file mode 100644
index 0000000..6a69a6f
--- /dev/null
+++ b/dot_config/i3/scripts/executable_memory
@@ -0,0 +1,69 @@
1#!/usr/bin/env bash
2# Copyright (C) 2014 Julien Bonjean <[email protected]>
3
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17TYPE="${BLOCK_INSTANCE:-mem}"
18
19awk -v type=$TYPE '
20/^MemTotal:/ {
21 mem_total=$2
22}
23/^MemFree:/ {
24 mem_free=$2
25}
26/^Buffers:/ {
27 mem_free+=$2
28}
29/^Cached:/ {
30 mem_free+=$2
31}
32/^SwapTotal:/ {
33 swap_total=$2
34}
35/^SwapFree:/ {
36 swap_free=$2
37}
38END {
39 if (type == "swap") {
40 free=swap_free/1024/1024
41 used=(swap_total-swap_free)/1024/1024
42 total=swap_total/1024/1024
43 } else {
44 free=mem_free/1024/1024
45 used=(mem_total-mem_free)/1024/1024
46 total=mem_total/1024/1024
47 }
48
49 pct=0
50 if (total > 0) {
51 pct=used/total*100
52 }
53
54 # full text
55 # printf("%.1fG/%.1fG (%.f%%)\n", used, total, pct)
56
57 # short text
58 printf("%.f%%\n", pct)
59
60 # color
61 if (pct > 90) {
62 print("#FF0000")
63 } else if (pct > 80) {
64 print("#FFAE00")
65 } else if (pct > 70) {
66 print("#FFF600")
67 }
68}
69' /proc/meminfo
Powered by cgit v1.2.3 (git 2.41.0)