-
Notifications
You must be signed in to change notification settings - Fork 0
/
i3bar.sh
executable file
·142 lines (122 loc) · 3.38 KB
/
i3bar.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
path="$(dirname "$0")"
bg_bar_color="#2E3440"
declare -A bgColor
declare -A fgColor
bgColor['ip']="#C49D58"
fgColor['ip']="#333333"
bgColor['disk']="#3949AB"
fgColor['disk']="#EEEEEE"
bgColor['mem']="#B87238"
fgColor['mem']="#DDDDDD"
bgColor['cpu']="#A7282E"
fgColor['cpu']="#FFFFFF"
bgColor['date']="#80B3B1"
fgColor['date']="#333333"
bgColor['vol']="#3B8E77"
fgColor['vol']="#222222"
separator() {
echo -n "{"
echo -n "\"full_text\":\"\"," # CTRL+Ue0b2
echo -n "\"separator\":false,"
echo -n "\"separator_block_width\":0,"
echo -n "\"border\":\"$bg_bar_color\","
echo -n "\"border_left\":0,"
echo -n "\"border_right\":0,"
echo -n "\"border_top\":0,"
echo -n "\"border_bottom\":0,"
echo -n "\"color\":\"$1\","
echo -n "\"background\":\"$2\""
echo -n "}"
}
common() {
echo -n "\"border\": \"$bg_bar_color\","
echo -n "\"separator\":false,"
echo -n "\"separator_block_width\":0,"
echo -n "\"border_top\":0,"
echo -n "\"border_bottom\":0,"
echo -n "\"border_left\":0,"
echo -n "\"border_right\":0"
}
myip_local() {
separator ${bgColor["ip"]} $bg_bar_color
echo -n ",{"
echo -n "\"name\":\"ip_local\","
echo -n "\"full_text\":\" $(ip route get 1 | sed -n 's/.*src \([0-9.]\+\).*/\1/p') \","
echo -n "\"color\":\"${fgColor['ip']}\","
echo -n "\"background\":\"${bgColor['ip']}\","
common
echo -n "},"
}
disk_usage() {
separator ${bgColor['disk']} ${bgColor['ip']}
echo -n ",{"
echo -n "\"name\":\"id_disk_usage\","
echo -n "\"full_text\":\" $($path/disk.py)% \" ,"
echo -n "\"color\":\"${fgColor['disk']}\","
echo -n "\"background\":\"${bgColor['disk']}\","
common
echo -n "},"
}
memory() {
separator ${bgColor['mem']} ${bgColor['disk']}
echo -n ",{"
echo -n "\"name\":\"id_memory\","
echo -n "\"full_text\":\" $($path/memory.py)% \","
echo -n "\"color\":\"${fgColor['mem']}\","
echo -n "\"background\":\"${bgColor['mem']}\","
common
echo -n "},"
}
cpu_usage() {
separator ${bgColor['cpu']} ${bgColor['mem']}
echo -n ",{"
echo -n "\"name\":\"id_cpu_usage\","
echo -n "\"full_text\":\" $($path/cpu.py)% \" ,"
echo -n "\"color\":\"${fgColor['cpu']}\","
echo -n "\"background\":\"${bgColor['cpu']}\","
common
echo -n "},"
}
mydate() {
separator ${bgColor['date']} ${bgColor['cpu']}
echo -n ",{"
echo -n "\"name\":\"id_time\","
echo -n "\"full_text\":\" $(date "+%a %d/%m %H:%M") \","
echo -n "\"color\":\"${fgColor['date']}\","
echo -n "\"background\":\"${bgColor['date']}\","
common
echo -n "},"
}
volume() {
separator ${bgColor['vol']} ${bgColor['date']}
vol=$(pamixer --get-volume)
echo -n ",{"
echo -n "\"name\":\"id_volume\","
if [ $vol -le 0 ]; then
echo -n "\"full_text\":\" ${vol}% \","
else
echo -n "\"full_text\":\" ${vol}% \","
fi
echo -n "\"color\":\"${fgColor['vol']}\","
echo -n "\"background\":\"${bgColor['vol']}\","
common
echo -n "},"
separator $bg_bar_color ${bgColor['vol']}
}
# https://github.com/i3/i3/blob/next/contrib/trivial-bar-script.sh
echo '{ "version": 1, "click_events":true }' # Send the header so that i3bar knows we want to use JSON:
echo '[' # Begin the endless array.
echo '[]' # We send an empty first array of blocks to make the loop simpler:
(while :;
do
echo -n ",["
myip_local
disk_usage
memory
cpu_usage
mydate
volume
echo "]"
sleep 10
done)