Files
hlwm-config/panel.sh
2018-04-03 23:17:34 +02:00

163 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
source ~/.config/herbstluftwm/settings.sh
# disable path name expansion or * will be expanded in the line
# cmd=( $line )
set -f
monitor=${1:-0}
monGeomitry=( $(herbstclient monitor_rect "$monitor") )
if [ -z "$monGeomitry" ] ;then
echo "Invalid monitor $monitor"
exit 1
fi
# monGeomitry has the format: WxH+X+Y
x=${monGeomitry[0]}
y=${monGeomitry[1]}
panel_width=$((${monGeomitry[2]}))
panel_height=20
# reserve space for tray on first monitor
if [ $monitor -eq 0 ] ; then
panel_width=$(($panel_width - 100))
fi
panelGeometry=${panel_width}x${panel_height}+${x}+${y}
textellipsis() {
awk -v len=100 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }'
}
volume() {
LEVEL=$(amixer get Master | tail -1 | sed 's/.*\[\([0-9]*\)%\].*/\1/')
if [ "$LEVEL" -gt "49" ] ; then
echo -en '\uf028';
elif [ "$LEVEL" -gt "0" ] ; then
echo -en '\uf027';
else
echo -en '\uf026';
fi
echo " ${LEVEL}%"
}
# events
{
# now playing
mpc idleloop player | cat &
mpc_pid=$!
# volume
while true ; do
echo -e "vol " $(volume)
sleep 1 || break
done > >(uniq_linebuffered) &
vol_pid=$!
# date
while true ; do
date +'date_min %Y-%m-%d %H:%M'
sleep 1 || break
done > >(uniq_linebuffered) &
date_pid=$!
# herbstluftwm
herbstclient --idle
# exiting; kill stray event-emitting processes
kill $mpc_pid $vol_pid $date_pid
} 2> /dev/null | {
TAGS=( $(herbstclient tag_status $monitor) )
unset TAGS[${#TAGS[@]}]
time=""
song=""
windowtitle=""
visible=true
while true ; do
echo -n "%{l}%{F-}"
for i in "${TAGS[@]}" ; do
case ${i:0:1} in
'#') # current tag
echo -n "%{U$active}%{+u}"
;;
'+') # active on other monitor
echo -n "%{U$activeOnMontior}%{+u}"
;;
':')
echo -n "%{F$notempty}"
;;
'!') # urgent tag
echo -n "%{U$urgent}%{+u}"
;;
*)
echo -n "%{F$notused}"
;;
esac
echo -n "%{A:select_tag ${i:1}:}"
echo -n " ${i:1} "
echo -n "%{A}"
echo -n "%{-u}%{F-}%{B-}"
done
# center window title
echo -n "%{c}$(echo ${windowtitle//^/^^} | textellipsis) "
# align right
echo -n "%{r}"
if [ -n "$song" ] ; then
echo -n "$song" "$song2"
fi
echo -en " $volume "
echo -en "\uf133 $date"
echo " "
# wait for next event
read line || break
cmd=( $line )
# find out event origin
case "${cmd[0]}" in
tag*)
TAGS=( $(herbstclient tag_status $monitor) )
unset TAGS[${#TAGS[@]}]
;;
mpd_player|player)
song="$(mpc -f %artist% current)"
song2="$(mpc -f %title% current)"
;;
vol)
volume="${cmd[@]:1}"
;;
date_min)
date="${cmd[@]:1}"
;;
focus_changed|window_title_changed)
windowtitle="${cmd[@]:2}"
;;
quit_panel)
exit
;;
reload)
exit
;;
esac
done
} 2> /dev/null \
| lemonbar \
-g $panelGeometry \
-f "$font" \
-B "$bgcolor" -F "$fgcolor" \
-u 2 \
| while read line; do
set $line
case "$1" in
select_tag )
# make sure the current monitor is focused
herbstclient focus_monitor $monitor
herbstclient use $2
;;
esac
done