configs/i3/conky_wrap.sh

48 lines
760 B
Bash
Executable File

#!/bin/sh
# Send the header so that i3bar knows we want to use JSON:
echo '{"version":1}'
# Begin the endless array.
echo '['
# We send an empty first array of blocks to make the loop simpler:
echo '[],'
cd $(dirname $0)
POTENTIAL_MPD_HOSTS="cubietruck mpid music.bingo localhost"
find_mpd() {
for host in $POTENTIAL_MPD_HOSTS
do
ping -c 1 $host >/dev/null 2>&1
if [ $? -eq 0 ]; then
NEW_HOST="$host"
break
fi
done
}
find_mpd
export MPD_HOST="$NEW_HOST"
while true
do
stdbuf -o L conky -c "conkyrc_$HOSTNAME" | stdbuf -i 0 -o 0 sed -f conky_bar.sed &
CHILD_PID=$!
NEW_HOST=$MPD_HOST
until [ "$NEW_HOST" != "$MPD_HOST" ]
do
sleep 300
find_mpd
done
kill $CHILD_PID >/dev/null 2>&1
sleep 3
export MPD_HOST="$NEW_HOST"
done