-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_i3status
132 lines (100 loc) · 3.09 KB
/
my_i3status
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
#!/bin/sh
battery_good=80
battery_warning=40
battery_alert=10
cWhite="#ffffff"
cGreen="#20e020"
cOrange="#ffe000"
cRed="#f00000"
function block {
echo '{ "color": "'"$1"'", "full_text": "'"$2"'", "short_text": "'"$3"'"}, '
}
function getSoundCards {
echo "$(aplay -l | awk 'BEGIN {lastN = ""}
/card/ {n = substr($2, 0, 1);
if (n != lastN) {
lastN = n;
printf n"="$3" "
}
}')"
}
# return "" if muted
function getSoundCardVolume {
soundCardInfo="$(amixer -c $1 sget Master)"
if [ -z "$soundCardInfo" ]; then
soundCardInfo="$(amixer -c $1 sget PCM 2>/dev/null)"
fi
if [ "$(echo "$soundCardInfo" | awk -F"[][]" '/dB/ { print $6; exit;}')" == "on" ]; then
echo "$(echo "$soundCardInfo" | awk -F"[][]" '/dB/ { print $2; exit;}')"
fi
}
i3status -c ~/.i3/i3status.conf | while :
do
read line
# SOUND VOLUME
sound=""
for i in $(getSoundCards); do
sound_cardId="$(echo $i | cut -d "=" -f 1)"
sound_cardName="$(echo $i | cut -d "=" -f 2)"
sound_cardVolume="$(getSoundCardVolume "$sound_cardId")"
if [ -z "$sound_cardVolume" ]; then
sound=$sound"$(block $cOrange "$sound_cardName " "$sound_cardId ")"
else
sound=$sound"$(block $cWhite "$sound_cardName $sound_cardVolume" "$sound_cardId $sound_cardVolume")"
fi
done
# WIRELESS
w_ip="$(ifconfig | grep -A 2 wlan0 | awk '/^\s+inet\W/ {print $2}')"
if [ -z "$w_ip" ]; then
wireless="$(block "$cRed" " not connected" " -")"
else
wireless="$(block "$cGreen" " $w_ip" " $w_ip")"
fi
# ETHERNET
e_ip="$(ifconfig | grep -A 2 enp0s10 | awk '/^\s+inet\W/ {print $2}')"
if [ -z "$e_ip" ]; then
ethernet="$(block "$cRed" " not connected" " -")"
else
ethernet="$(block "$cGreen" " $e_ip" " $e_ip")"
fi
# IPV6
ipv6_ip="";
if [ "$w_ip" ]; then
ipv6_ip="$(ifconfig | grep -A 2 wlan0 | awk '/^\s+inet6\W/ {print $2}')"
fi
if [ -z "$ipv6_ip" -a "$e_ip" ]; then
ipv6_ip="$(ifconfig | grep -A 2 enp0s10 | awk '/^\s+inet6\W/ {print $2}')"
echo "asdkine $ipv6_ip" > /tmp/cards
fi
if [ "$ipv6_ip" ]; then
ipv6="$(block "$cGreen" "IPv6 $ipv6_ip" "$ipv6_ip")"
else
ipv6=""
fi
# BATTERY
b_charging=$(if [ "$(acpi | awk '{print $3}')" == "Charging," ]; then
echo ""
fi)
b_charge_percent=$(acpi | awk 'BEGIN {FS="[% ]"} /Battery/ {print $4}')
b_logos=" "
for i in `seq 1 5`; do
if [ "$b_charge_percent" -ge "$(echo "($i-1)*20" | bc)" ]; then
b_logo="$(echo "$b_logos" | cut -d " " -f $i )"
fi
done
if [ "$b_charge_percent" -le "$battery_alert" ]; then
b_color="$cRed"
elif [ "$b_charge_percent" -le "$battery_warning" ]; then
b_color="$cOrange"
elif [ "$b_charge_percent" -ge "$battery_good" ]; then
b_color="$cGreen"
else
b_color="$cWhite"
fi
battery="$(block "$b_color" "$b_charging $b_logo $b_charge_percent%" "$b_logo $b_charge_percent%" )"
# LIGHT
bl_brightness="$(block "$cWhite" "☀ $(sh ~/.i3/bl-brightness.sh)%" "☀ $(sh ~/.i3/bl-brightness.sh)%")"
light="$(block "$cWhite" "☀ $(brightness)%" "☀ $(brightness)%")"
# ECHO
echo "${line/'['/'['$ethernet$wireless$ipv6$light$battery$sound}" || exit 1
done