Multiprocess bar :D

This commit is contained in:
madmaurice 2015-06-10 08:33:16 +02:00
parent 5fb95bcab3
commit b056804a8c
2 changed files with 82 additions and 50 deletions

View file

@ -2,7 +2,7 @@
FIFO="/tmp/bar.fifo"
FORMAT_LEFT="%(music)s %(services)s %(diskspace)s"
FORMAT_LEFT=" %(music)s %(services)s %(diskspace)s"
FORMAT_RIGHT="%(wifi)s %(battery)s %(clock)s "
icon_color="#A0A57E"
@ -24,16 +24,20 @@ color_battery_good="white"
color_battery_low="#C37561"
music() {
while true; do
info=$(mpc current -f '[%title%]')
icon=$icon_music
if [ -n "$info" ]; then
if [ -n "$(mpc status | grep paused)" ]; then
icon=$icon_music_paused
fi
echo -n "%{A:I "music 20":}$icon $info%{A}"
echo music "%{A:I music 20:}$icon $info%{A}" > $FIFO;
else
echo -n "$icon (-)"
echo music "$icon (-)" > $FIFO;
fi
mpc idle >/dev/null;
done;
}
serviceinfo() {
@ -48,24 +52,37 @@ serviceinfo() {
}
services() {
echo -n "$icon_services $(serviceinfo zomnet z) $(serviceinfo docker d)"
while true; do
info="$icon_services $(serviceinfo zomnet z)"
echo services $info > $FIFO;
sleep 5;
done;
}
diskspace() {
info=$(./cmdcache.sh 10 "df -h /" | awk '{if($6 == "/") { print $5 }}')
echo -n "%{A:I "filesystem 30":}$icon_diskspace $info%{A}"
while true; do
info=$(df -h / | awk '{if($6 == "/") { print $5 }}')
echo diskspace "%{A:I filesystem 30:}$icon_diskspace $info%{A}" > $FIFO;
sleep 20;
done;
}
wifi() {
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
echo -n "%{A:I "network 1061":}$icon_wifi $info%{A}"
echo wifi "%{A:I network 1061:}$icon_wifi $info%{A}" > $FIFO;
sleep 1;
done;
}
battery() {
level=$(./cmdcache.sh 5 "acpi -b" | awk -F, 'BEGIN { s=0 } { s+=$2 } END { print int(s/NR) }')
while true; do
level=$(acpi -b | awk -F, 'BEGIN { s=0 } { s+=$2 } END { print int(s/NR) }')
charging=$(acpi -a | grep on-line)
icon=$icon_battery
@ -77,17 +94,29 @@ battery() {
info="%{F$color_battery_low}$level%%{F-}"
fi
echo -n "%{A:I 'battery 1061':}$icon $info%{A}"
echo battery "%{A:I battery 1061:}$icon $info%{A}" > $FIFO
sleep 5;
done;
}
clock() {
while true; do
info=$(date +"%H:%M")
echo -n "%{A:I "clock 1061":}$icon_clock $info%{A}"
#Bad hack: convert to int to remove leading 0s
seconds_to_wait=$[ 61 - $(date +"%S" | awk '{print int($0)}') ];
echo clock "%{A:I "clock 1061":}$icon_clock $info%{A}" > $FIFO;
sleep $seconds_to_wait
done;
}
updates() {
updates=$(./cmdcache.sh 20 ./pkginfo.sh)
while true; do
updates=$(pkginfo.sh)
echo -n "$icon_updates $updates"
sleep 20
done
}
run_handler() {
@ -101,26 +130,22 @@ run_handler() {
done
}
run_worker() {
SLEEP=$1
TAG=$2
COMMAND=$3
( while true; do
echo -n "$TAG "
$COMMAND
echo
sleep $SLEEP
done > $FIFO ) &
}
cd $(dirname $0)
#Trap magic
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
#Fifo
[ -e "$FIFO" ] && rm -f $FIFO
mkfifo $FIFO
#start workers
clock &
battery &
music &
services &
diskspace &
wifi &
run_worker 1 clock clock
run_worker 5 battery battery
( while true; do cat $FIFO; done ) | python ./barformatter.py "$FORMAT_LEFT" "$FORMAT_RIGHT" # | lemonbar -g 1366x15 -f "Stlarch:size=6:style=regular" -f "Terminus:size=8" -B "#88000000" | run_handler
( while true; do cat $FIFO; done ) | python ./barformatter.py "$FORMAT_LEFT" "$FORMAT_RIGHT" | lemonbar -g 1366x15 -f "Stlarch:size=6:style=regular" -f "Terminus:size=8" -B "#88000000" | run_handler

View file

@ -6,6 +6,10 @@ header(){
echo "%{F$HEADER_COLOR}$1%{F-}"
}
tag() {
echo -n "%{F#HEADER_COLOR}$1:${F-}%{r}"
}
### Filesystem info
filesystem() {
@ -24,7 +28,10 @@ network() {
### Music info
music() {
header "Music"
mpc current -f "$(header Artist:) %artist%\n$(header Album:) %album%\n$(header Title:) %title%"
#mpc current -f "$(header Artist:) %artist%\n$(header Album:) %album%\n$(header Title:) %title%"
tag "Artist"; mpc current -f "%artist%"
tag "Album"; mpc current -f "%album%"
tag "Title"; mpc current -f "%title%"
}
### Battery info