-
Notifications
You must be signed in to change notification settings - Fork 1
/
swaybar.sh
183 lines (158 loc) · 4.27 KB
/
swaybar.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/sh
# sway config in ~/.config/sway/config :
# bar {
# status_command exec ~/.config/sway/swaybar.sh
# }
bg_bar_color="#323232"
# Print a left caret separator
# @params {string} $1 text color, ex: "#FF0000"
# @params {string} $2 background color, ex: "#FF0000"
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\":2,"
echo -n "\"border_bottom\":2,"
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\":2,"
echo -n "\"border_bottom\":2,"
echo -n "\"border_left\":0,"
echo -n "\"border_right\":0"
}
shortcuts() {
local bg="#639bd3" # vert
separator $bg $bg_bar_color
echo -n ",{"
echo -n "\"name\":\"id_shortcuts\","
echo -n "\"full_text\":\" $(localectl status | grep "X11 Layout" | sed -e "s/^.*X11 Layout://")\","
echo -n "\"background\":\"$bg\","
common
echo -n "},"
}
conn() {
local bg="#2E7D32" # vert
separator $bg "#639bd3"
echo -n ",{"
echo -n "\"name\":\"id_conn\","
echo -n "\"full_text\":\" $(nmcli -t -f NAME c show --active) \","
echo -n "\"background\":\"$bg\","
common
echo -n "},"
}
mem_usage() {
local bg="#3949AB"
separator $bg "#2E7D32"
echo -n ",{"
echo -n "\"name\":\"id_mem_usage\","
echo -n "\"full_text\":\" $(awk '/^Mem/ {print $3}' <(free -m))M \","
echo -n "\"background\":\"#3949AB\","
common
echo -n "},"
}
mydate() {
local bg="#E0E0E0"
separator $bg "#3949AB"
echo -n ",{"
echo -n "\"name\":\"id_time\","
echo -n "\"full_text\":\" $(date "+%H:%M") \","
echo -n "\"color\":\"#000000\","
echo -n "\"background\":\"$bg\","
common
echo -n "},"
}
battery0() {
if [ -f /sys/class/power_supply/BAT0/uevent ]; then
local bg="#D69E2E"
separator $bg "#E0E0E0"
bg_separator_previous=$bg
prct=$(cat /sys/class/power_supply/BAT0/uevent | grep "POWER_SUPPLY_CAPACITY=" | cut -d'=' -f2)
charging=$(cat /sys/class/power_supply/BAT0/uevent | grep "POWER_SUPPLY_STATUS" | cut -d'=' -f2) # POWER_SUPPLY_STATUS=Discharging|Charging
icon=""
if [ "$charging" == "Charging" ]; then
icon=""
fi
echo -n ",{"
echo -n "\"name\":\"battery0\","
echo -n "\"full_text\":\" ${icon} ${prct}% \","
echo -n "\"color\":\"#000000\","
echo -n "\"background\":\"$bg\","
common
echo -n "},"
else
bg_separator_previous="#E0E0E0"
fi
}
volume() {
local bg="#673AB7"
separator $bg $bg_separator_previous
vol=$(awk -F"[][]" '/Left:/ { print $2 }' <(amixer sget Master))
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 "\"background\":\"$bg\","
common
echo -n "},"
separator $bg_bar_color $bg
}
logout() {
echo -n ",{"
echo -n "\"name\":\"id_logout\","
echo -n "\"full_text\":\" \""
echo -n "}"
}
# 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:
# Now send blocks with information forever:
(while :;
do
echo -n ",["
shortcuts
conn
mem_usage
mydate
battery0
volume
logout
echo "]"
sleep 10
done) &
# click events
while read line;
do
# TERMINAL
if [[ $line == *"name"*"id_shortcuts"* ]]; then
qterminal -e ~/.config/sway/shortcuts.sh &
# CONNECTION
elif [[ $line == *"name"*"id_conn"* ]]; then
qterminal -e nmtui &
# MEMORY
elif [[ $line == *"name"*"id_mem_usage"* ]]; then
qterminal -e htop &
# TIME
elif [[ $line == *"name"*"id_time"* ]]; then
qterminal -e ~/.config/sway/click_time.sh &
# VOLUME
elif [[ $line == *"name"*"id_volume"* ]]; then
qterminal -e pavucontrol-qt &
# LOGOUT
elif [[ $line == *"name"*"id_logout"* ]]; then
swaymsg exit &
fi
done