Multiprocess bar :D
This commit is contained in:
parent
5fb95bcab3
commit
b056804a8c
2 changed files with 82 additions and 50 deletions
123
scripts/bar.sh
123
scripts/bar.sh
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
FIFO="/tmp/bar.fifo"
|
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 "
|
FORMAT_RIGHT="%(wifi)s %(battery)s %(clock)s "
|
||||||
|
|
||||||
icon_color="#A0A57E"
|
icon_color="#A0A57E"
|
||||||
|
@ -24,16 +24,20 @@ color_battery_good="white"
|
||||||
color_battery_low="#C37561"
|
color_battery_low="#C37561"
|
||||||
|
|
||||||
music() {
|
music() {
|
||||||
info=$(mpc current -f '[%title%]')
|
while true; do
|
||||||
icon=$icon_music
|
info=$(mpc current -f '[%title%]')
|
||||||
if [ -n "$info" ]; then
|
icon=$icon_music
|
||||||
if [ -n "$(mpc status | grep paused)" ]; then
|
if [ -n "$info" ]; then
|
||||||
icon=$icon_music_paused
|
if [ -n "$(mpc status | grep paused)" ]; then
|
||||||
|
icon=$icon_music_paused
|
||||||
|
fi
|
||||||
|
echo music "%{A:I music 20:}$icon $info%{A}" > $FIFO;
|
||||||
|
else
|
||||||
|
echo music "$icon (-)" > $FIFO;
|
||||||
fi
|
fi
|
||||||
echo -n "%{A:I "music 20":}$icon $info%{A}"
|
|
||||||
else
|
mpc idle >/dev/null;
|
||||||
echo -n "$icon (-)"
|
done;
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceinfo() {
|
serviceinfo() {
|
||||||
|
@ -48,46 +52,71 @@ serviceinfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
services() {
|
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() {
|
diskspace() {
|
||||||
info=$(./cmdcache.sh 10 "df -h /" | awk '{if($6 == "/") { print $5 }}')
|
while true; do
|
||||||
echo -n "%{A:I "filesystem 30":}$icon_diskspace $info%{A}"
|
info=$(df -h / | awk '{if($6 == "/") { print $5 }}')
|
||||||
|
echo diskspace "%{A:I filesystem 30:}$icon_diskspace $info%{A}" > $FIFO;
|
||||||
|
|
||||||
|
sleep 20;
|
||||||
|
done;
|
||||||
}
|
}
|
||||||
|
|
||||||
wifi() {
|
wifi() {
|
||||||
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; } }')
|
while true; do
|
||||||
if [ -z "$info" ]; then
|
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; } }')
|
||||||
info="(-)"
|
if [ -z "$info" ]; then
|
||||||
fi
|
info="(-)"
|
||||||
echo -n "%{A:I "network 1061":}$icon_wifi $info%{A}"
|
fi
|
||||||
|
echo wifi "%{A:I network 1061:}$icon_wifi $info%{A}" > $FIFO;
|
||||||
|
|
||||||
|
sleep 1;
|
||||||
|
done;
|
||||||
}
|
}
|
||||||
|
|
||||||
battery() {
|
battery() {
|
||||||
level=$(./cmdcache.sh 5 "acpi -b" | awk -F, 'BEGIN { s=0 } { s+=$2 } END { print int(s/NR) }')
|
while true; do
|
||||||
charging=$(acpi -a | grep on-line)
|
level=$(acpi -b | awk -F, 'BEGIN { s=0 } { s+=$2 } END { print int(s/NR) }')
|
||||||
|
charging=$(acpi -a | grep on-line)
|
||||||
|
|
||||||
icon=$icon_battery
|
icon=$icon_battery
|
||||||
if [ -n "$charging" ]; then
|
if [ -n "$charging" ]; then
|
||||||
icon=$icon_battery_charging
|
icon=$icon_battery_charging
|
||||||
fi
|
fi
|
||||||
info="%{F$color_battery_good}$level%%{F-}"
|
info="%{F$color_battery_good}$level%%{F-}"
|
||||||
if [ "$level" -lt 20 ]; then
|
if [ "$level" -lt 20 ]; then
|
||||||
info="%{F$color_battery_low}$level%%{F-}"
|
info="%{F$color_battery_low}$level%%{F-}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "%{A:I 'battery 1061':}$icon $info%{A}"
|
echo battery "%{A:I battery 1061:}$icon $info%{A}" > $FIFO
|
||||||
|
|
||||||
|
sleep 5;
|
||||||
|
done;
|
||||||
}
|
}
|
||||||
|
|
||||||
clock() {
|
clock() {
|
||||||
info=$(date +"%H:%M")
|
while true; do
|
||||||
echo -n "%{A:I "clock 1061":}$icon_clock $info%{A}"
|
info=$(date +"%H:%M")
|
||||||
|
#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() {
|
||||||
updates=$(./cmdcache.sh 20 ./pkginfo.sh)
|
while true; do
|
||||||
echo -n "$icon_updates $updates"
|
updates=$(pkginfo.sh)
|
||||||
|
echo -n "$icon_updates $updates"
|
||||||
|
sleep 20
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
run_handler() {
|
run_handler() {
|
||||||
|
@ -101,26 +130,22 @@ run_handler() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
run_worker() {
|
|
||||||
SLEEP=$1
|
|
||||||
TAG=$2
|
|
||||||
COMMAND=$3
|
|
||||||
( while true; do
|
|
||||||
echo -n "$TAG "
|
|
||||||
$COMMAND
|
|
||||||
echo
|
|
||||||
sleep $SLEEP
|
|
||||||
done > $FIFO ) &
|
|
||||||
}
|
|
||||||
|
|
||||||
cd $(dirname $0)
|
cd $(dirname $0)
|
||||||
|
|
||||||
|
#Trap magic
|
||||||
|
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
|
||||||
|
|
||||||
|
#Fifo
|
||||||
[ -e "$FIFO" ] && rm -f $FIFO
|
[ -e "$FIFO" ] && rm -f $FIFO
|
||||||
mkfifo $FIFO
|
mkfifo $FIFO
|
||||||
|
|
||||||
|
#start workers
|
||||||
|
clock &
|
||||||
|
battery &
|
||||||
|
music &
|
||||||
|
services &
|
||||||
|
diskspace &
|
||||||
|
wifi &
|
||||||
|
|
||||||
run_worker 1 clock clock
|
( 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
|
||||||
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
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,10 @@ header(){
|
||||||
echo "%{F$HEADER_COLOR}$1%{F-}"
|
echo "%{F$HEADER_COLOR}$1%{F-}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tag() {
|
||||||
|
echo -n "%{F#HEADER_COLOR}$1:${F-}%{r}"
|
||||||
|
}
|
||||||
|
|
||||||
### Filesystem info
|
### Filesystem info
|
||||||
|
|
||||||
filesystem() {
|
filesystem() {
|
||||||
|
@ -24,7 +28,10 @@ network() {
|
||||||
### Music info
|
### Music info
|
||||||
music() {
|
music() {
|
||||||
header "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
|
### Battery info
|
||||||
|
|
Loading…
Reference in a new issue