This repository has been archived by the owner on Aug 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i3bar
executable file
·183 lines (167 loc) · 4.64 KB
/
i3bar
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/bash
#Some functions to make displaying stuff easier
function hexcolor {
bat=$1
red=$(echo 255-$bat*2.55 | bc)
green=$(echo $bat*2.55 | bc)
green=$(echo "obase=16; ${green%.*}" | bc)
red=$(echo "obase=16; ${red%.*}" | bc)
if [ ${#red} = 1 ]; then
red="0"$red
fi
if [ ${#green} = 1 ]; then
green="0"$green
fi
hexcolor="#"$red$green"00"
}
function print {
message=$1
color=$2
echo '{"full_text":"'$message'","color":"'$color'"},'
}
#Some functions to setup and get info we don't want to be constantly be asking for
function setup {
white="#ffffff"
green="#00ff00"
red="#ff0000"
firstRunVPN=0 #we're just going to assume we are connected to a vpn until told otherwise
}
function getIPs {
LOCALIP=$(command ifconfig wlp1s0 | grep "inet addr")
LOCALIP=${LOCALIP%%B*0}
LEN=${#LOCALIP}
LOCALIP=${LOCALIP:20:$LEN-22}
IP=$(command wget -qO- http://ipecho.net/plain ; echo)
}
#prints whatever is in my to do list
function toDo {
filename="/home/blemay360/.todo"
comment=0
notify=0
while read -r line || [[ -n "$line" ]]; do
if [ "${line:0:2}" != "//" ] && [ "$line" != "" ] && [ "${line:0:1}" != "#" ]; then
if [ "${line:0:12}" = "Notification" ]; then
notify=1
comment=1
elif [ $comment -eq 1 ]; then
notify=0
else
notify=0
comment=0
fi
if [ "${line:0:1}" = "!" ]; then
print "${line:1}" $red
elif [ "${line:0:2}" = "/*" ]; then
let comment=1
elif [ "${line:0:2}" = "*/" ]; then
let comment=0
elif [ $comment -eq 0 ]; then
print "$line" $white
fi
fi
done < $filename
}
toDo="Store each notification in ascending order of display time, so the first line will be displayed first, and the second second.. From there, the notify flag will be repurposed to work be the time. Then just check the notify flag time to display whatever is in the file"
function depositNotification {
echo $1 >> notifications.txt
}
function printNotification {
notify-send $(head -n 1 notifications.txt)
$(sed '1d' notifications.txt)
}
function batperc {
BATPERC=$(command upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "percentage")
BATPERC=${BATPERC:24}
bat=${BATPERC::-1}
hexcolor $bat
print $BATPERC $hexcolor
}
#functions for retreiving the battery status
function batstat {
green="#00ff00"
red="#ff0000"
BATSTAT=$(command upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "state")
BATSTAT=${BATSTAT:25}
if [ $BATSTAT = "discharging" ] && [ $bat -le 15 ]; then
print "Discharging" $red
elif [ $BATSTAT = "discharging" ]; then
print "Discharging" $white
elif [ $BATSTAT = "charging" ]; then
print "Charging" $green
elif [ $BATSTAT = "fully-charged" ]; then
print "Charged" $green
fi
}
#some functions for what's going on with the wifi connection
function network {
NETWORK="$(command iwconfig wlp1s0 | grep ESSID:"*")"
NETWORK=${NETWORK:30:-3}
if [ "$NETWORK" = "Bedly - 137 - 1R" ]; then
print "Apartment" $white
else
print "$NETWORK" $white
fi
# if [ "$prevNetwork" != "$NETWORK" ]; then
# sleep 3
# getIPs
# fi
# prevNetwork="$NETWORK"
}
#function printIPaddrs {
#only prints out local and public ip address
# print $LOCALIP $white
# print $IP $white
#}
function vpn {
#queries TUN0 to see if a vpn is enabled. If it is, it will give a whole message, otherwise it will give a short error
TUN0=$(command ifconfig -a)
if [ ${#TUN0} -gt 1200 ]; then
if [ "$firstRunVPN" -eq 0 ]; then
let firstRunVPN=1
fi
echo {'"full_text":"VPN","color":"'$green'"'},
elif [ "$firstRunVPN" -eq 1 ]; then
let firstRunVPN=0
fi
}
#prints the time until next class
function nextClass {
if [ "$last_run" = "" ]; then
nextClass=$(bash /home/blemay360/bin/classSchedule/classSchedule.sh)
lastrun="$(command date "+%M")"
elif [ "$last_run" != $(command date "+%M") ]; then
nextClass=$(bash /home/blemay360/bin/classSchedule/classSchedule.sh)
lastrun="$(command date "+%M")"
fi
if [ "$nextClass" != "" ]; then
print $nextClass $white
fi
}
#Prints date and time
function printdate {
#retrieves date and prints it out. Only called printdate because calling it date made it recursive and crashed stuff
print "$(command date "+%a %b %d")" $white
print $(command date "+%H:%M:%S") $white
}
function keyboardStatus {
filename="/home/blemay360/bin-master/toggleKeyboardMouse/.state"
state=$(cat $filename)
if [ $(cat $filename) -eq 1 ]; then
print "Touchpad disabled" $red
fi
}
function main {
echo "[" #starts packet
toDo
keyboardStatus
batperc
batstat
network
vpn
# nextClass
printdate
echo '{"full_text":""}],' #ends packet
main #iterates to send the next packet
}
setup
main