2015-05-29 21:08:06 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-06-09 22:41:53 +02:00
|
|
|
FIFO="/tmp/bar.fifo"
|
|
|
|
|
2015-10-11 16:10:56 +02:00
|
|
|
FORMAT=" %(music)s %(services)s %(diskspace)s %%{c} %(debug)s %%{r} %(updates)s %(wifi)s %(batterysymbol)s %(battery)s %(clock)s "
|
2015-06-05 01:04:15 +02:00
|
|
|
|
2015-07-03 16:57:43 +02:00
|
|
|
icon_color="#AAAAAA"
|
2015-05-29 21:08:06 +02:00
|
|
|
icon() { echo -n "%{F$icon_color}"; printf '%b' "\ue$1"; echo -n "%{F-}"; }
|
|
|
|
|
|
|
|
icon_music=$(icon 05c)
|
|
|
|
icon_music_paused=$(icon 059)
|
|
|
|
icon_services=$(icon 040)
|
|
|
|
icon_diskspace=$(icon 0ab)
|
|
|
|
icon_wifi=$(icon 048)
|
|
|
|
icon_battery=$(icon 033)
|
|
|
|
icon_battery_charging=$(icon 042)
|
|
|
|
icon_clock=$(icon 018)
|
2015-06-08 08:37:42 +02:00
|
|
|
icon_updates=$(icon 060)
|
2015-05-29 21:08:06 +02:00
|
|
|
|
2015-07-03 16:57:43 +02:00
|
|
|
color_service_running="#EEEEEE"
|
|
|
|
color_service_stopped="#666666"
|
|
|
|
color_battery_good="#EEEEEE"
|
2015-05-29 21:08:06 +02:00
|
|
|
color_battery_low="#C37561"
|
|
|
|
|
|
|
|
music() {
|
2015-06-10 08:33:16 +02:00
|
|
|
while true; do
|
2015-10-11 16:10:56 +02:00
|
|
|
info=$(mpc current -f '[%artist%] - [%title%]')
|
2015-06-10 08:33:16 +02:00
|
|
|
icon=$icon_music
|
|
|
|
if [ -n "$info" ]; then
|
|
|
|
if [ -n "$(mpc status | grep paused)" ]; then
|
|
|
|
icon=$icon_music_paused
|
|
|
|
fi
|
2015-10-11 16:10:56 +02:00
|
|
|
echo music "$icon $info" > $FIFO;
|
2015-06-10 08:33:16 +02:00
|
|
|
else
|
|
|
|
echo music "$icon (-)" > $FIFO;
|
2015-06-05 01:04:15 +02:00
|
|
|
fi
|
2015-06-10 08:33:16 +02:00
|
|
|
|
|
|
|
mpc idle >/dev/null;
|
|
|
|
done;
|
2015-05-29 21:08:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
serviceinfo() {
|
|
|
|
service=$1
|
|
|
|
text=$2
|
|
|
|
systemctl is-active -q $service
|
|
|
|
if [ "$?" -eq 0 ]; then
|
|
|
|
echo -n "%{F$color_service_running}$text%{F-}"
|
|
|
|
else
|
|
|
|
echo -n "%{F$color_service_stopped}$text%{F-}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
services() {
|
2015-06-10 08:33:16 +02:00
|
|
|
while true; do
|
|
|
|
info="$icon_services $(serviceinfo zomnet z)"
|
|
|
|
echo services $info > $FIFO;
|
|
|
|
sleep 5;
|
|
|
|
done;
|
2015-05-29 21:08:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
diskspace() {
|
2015-06-10 08:33:16 +02:00
|
|
|
while true; do
|
|
|
|
info=$(df -h / | awk '{if($6 == "/") { print $5 }}')
|
2015-10-11 16:10:56 +02:00
|
|
|
echo diskspace "$icon_diskspace $info" > $FIFO;
|
2015-12-03 17:59:58 +01:00
|
|
|
|
2015-06-10 08:33:16 +02:00
|
|
|
sleep 20;
|
|
|
|
done;
|
2015-05-29 21:08:06 +02:00
|
|
|
}
|
|
|
|
|
2016-11-05 22:22:30 +01:00
|
|
|
wifi_wicd() {
|
2015-06-10 08:33:16 +02:00
|
|
|
while true; do
|
|
|
|
info=$(wicd-cli --wireless --status | perl -e 'foreach $line (<>) { if($line =~ /Connected to (.+) at .+IP: ([0-9.]+)/ ) { print $1; break; } elsif($line =~ /Connecting to wireless network \"(.+)\"/) { print $1 . " - connecting"; break; } }')
|
|
|
|
if [ -z "$info" ]; then
|
|
|
|
info="(-)"
|
|
|
|
fi
|
2015-10-11 16:10:56 +02:00
|
|
|
echo wifi "$icon_wifi $info" > $FIFO;
|
2015-06-10 08:33:16 +02:00
|
|
|
|
|
|
|
sleep 1;
|
|
|
|
done;
|
2015-05-29 21:08:06 +02:00
|
|
|
}
|
|
|
|
|
2016-11-05 22:22:30 +01:00
|
|
|
wifi_nm() {
|
|
|
|
while true; do
|
|
|
|
info=$(nmcli -t -f state,connection d | awk -F: '{ if($1=="connected") { print $2; exit; } }')
|
|
|
|
if [ -z "$info" ]; then
|
|
|
|
info="(-)"
|
|
|
|
fi
|
|
|
|
echo wifi "$icon_wifi $info" > $FIFO;
|
|
|
|
|
|
|
|
sleep 2;
|
|
|
|
done;
|
|
|
|
}
|
|
|
|
|
2015-05-29 21:08:06 +02:00
|
|
|
battery() {
|
2015-06-10 08:33:16 +02:00
|
|
|
while true; do
|
|
|
|
level=$(acpi -b | awk -F, 'BEGIN { s=0 } { s+=$2 } END { print int(s/NR) }')
|
2015-06-05 01:04:15 +02:00
|
|
|
|
2015-06-10 08:33:16 +02:00
|
|
|
info="%{F$color_battery_good}$level%%{F-}"
|
|
|
|
if [ "$level" -lt 20 ]; then
|
|
|
|
info="%{F$color_battery_low}$level%%{F-}"
|
|
|
|
fi
|
2015-12-03 17:59:58 +01:00
|
|
|
|
2015-10-11 16:10:56 +02:00
|
|
|
echo battery "$info" > $FIFO
|
2015-06-30 14:27:05 +02:00
|
|
|
|
2015-09-08 05:54:26 +02:00
|
|
|
sleep 2m;
|
2015-06-30 14:27:05 +02:00
|
|
|
done;
|
2015-06-12 00:01:05 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 16:10:56 +02:00
|
|
|
batterysymbol() {
|
|
|
|
while true; do
|
|
|
|
icon=$icon_battery
|
|
|
|
[ -n "$(acpi -a | grep on-line)" ] && icon=$icon_battery_charging
|
|
|
|
|
|
|
|
echo batterysymbol "$icon" > $FIFO
|
2015-12-03 17:59:58 +01:00
|
|
|
|
2015-10-11 16:10:56 +02:00
|
|
|
sleep 5;
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2015-05-29 21:08:06 +02:00
|
|
|
clock() {
|
2015-06-10 08:33:16 +02:00
|
|
|
while true; do
|
2015-10-12 21:43:31 +02:00
|
|
|
info=$(date +"%d.%m. (%V) %H:%M")
|
2015-06-10 08:33:16 +02:00
|
|
|
#Bad hack: convert to int to remove leading 0s
|
|
|
|
seconds_to_wait=$[ 61 - $(date +"%S" | awk '{print int($0)}') ];
|
2015-06-26 08:46:42 +02:00
|
|
|
if [ "$seconds_to_wait" -gt 10 ]; then
|
|
|
|
seconds_to_wait=10
|
|
|
|
fi
|
2015-10-11 16:10:56 +02:00
|
|
|
echo clock "$icon_clock $info" > $FIFO;
|
2015-12-03 17:59:58 +01:00
|
|
|
|
2015-06-10 08:33:16 +02:00
|
|
|
sleep $seconds_to_wait
|
|
|
|
done;
|
2015-06-05 01:04:15 +02:00
|
|
|
}
|
|
|
|
|
2015-06-08 08:37:42 +02:00
|
|
|
updates() {
|
2015-06-19 03:34:48 +02:00
|
|
|
pac_updates() {
|
|
|
|
checkupdates | wc -l
|
|
|
|
}
|
|
|
|
|
|
|
|
aur_updates() {
|
|
|
|
yaourt -Quaq | wc -l
|
|
|
|
}
|
|
|
|
|
|
|
|
useless_packages() {
|
|
|
|
pacman -Qtdq | wc -l
|
|
|
|
}
|
|
|
|
|
2015-06-10 08:33:16 +02:00
|
|
|
while true; do
|
2016-11-05 22:22:30 +01:00
|
|
|
internet=$(nmcli -t -f state d | grep connected)
|
2015-10-11 16:10:56 +02:00
|
|
|
if [ -z "$internet" ]; then
|
2015-06-19 03:34:48 +02:00
|
|
|
if [ -z "$pac" ]; then
|
|
|
|
pac=?
|
|
|
|
fi
|
|
|
|
if [ -z "$aur" ]; then
|
|
|
|
aur=?
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
pac=$(pac_updates)
|
|
|
|
aur=$(aur_updates)
|
|
|
|
fi
|
|
|
|
|
|
|
|
useless=$(useless_packages)
|
|
|
|
|
|
|
|
updates="$pac+$aur-$useless"
|
|
|
|
|
2015-06-10 08:43:17 +02:00
|
|
|
echo updates "$icon_updates $updates" > $FIFO;
|
2015-06-10 08:33:16 +02:00
|
|
|
sleep 20
|
|
|
|
done
|
2015-06-08 08:37:42 +02:00
|
|
|
}
|
|
|
|
|
2015-06-09 22:41:53 +02:00
|
|
|
cd $(dirname $0)
|
|
|
|
|
2015-06-10 08:33:16 +02:00
|
|
|
#Fifo
|
2015-06-09 22:41:53 +02:00
|
|
|
[ -e "$FIFO" ] && rm -f $FIFO
|
|
|
|
mkfifo $FIFO
|
|
|
|
|
2015-06-10 08:33:16 +02:00
|
|
|
#start workers
|
|
|
|
clock &
|
|
|
|
battery &
|
2015-10-11 16:10:56 +02:00
|
|
|
batterysymbol &
|
2015-06-10 08:33:16 +02:00
|
|
|
music &
|
|
|
|
services &
|
|
|
|
diskspace &
|
2016-11-05 22:22:30 +01:00
|
|
|
wifi_nm &
|
2015-06-10 08:43:17 +02:00
|
|
|
updates &
|
2015-06-09 22:41:53 +02:00
|
|
|
|
2015-12-03 17:59:58 +01:00
|
|
|
#Trap magic
|
|
|
|
trap "kill -9 -$$" TERM INT
|
|
|
|
echo Trap set for $$
|
|
|
|
|
|
|
|
(
|
|
|
|
( while [ -e "$FIFO" ]; do cat $FIFO; done ) | python ./barformatter.py "$FORMAT" | lemonbar -g 1366x18 -f "Stlarch:size=6:style=regular" -f "Inconsolata:size=8" -B "#88000000"
|
|
|
|
) &
|
2015-05-29 21:08:06 +02:00
|
|
|
|
2015-12-03 17:59:58 +01:00
|
|
|
wait $!
|