legacy-dotfiles/.config/herbstluftwm/panel.sh

157 lines
4.6 KiB
Bash
Raw Normal View History

#!/bin/bash
monitor=${1:-0}
monitor2=1
geometry=( $(herbstclient monitor_rect "$monitor") )
if [ -z "$geometry" ] ;then
echo "Invalid monitor $monitor"
exit 1
fi
# geometry has the format: WxH+X+Y
x=${geometry[0]}
width=${geometry[2]}
2012-02-06 22:28:14 +01:00
height=12
2012-01-31 16:03:40 +01:00
y=$(expr ${geometry[3]} - $height)
tag_width=40
2011-12-23 13:38:22 +01:00
font="-misc-tamsyn-medium-r-normal-*-14-*-*-*-*-*-iso8859-*"
selcolor='#24c6e0'
locolor='#15abc3'
bgcolor='#000000'
hicolor="#808080"
urcolor="#e0c625"
function uniq_linebuffered() {
awk '$0 != l { print ; l=$0 ; fflush(); }' "$@"
}
2012-02-06 22:28:14 +01:00
function print_tags() {
# draw tags
echo -n "$separator"
for i in "${TAGS[@]}" ; do
if [[ "${TAGS2[@]}" == *"#${i:1}"* ]]; then
echo -n "^bg($selcolor)^fg(#000000) ${i:1} ^fg()^bg()"
# echo -n "^fg($selcolor)^ro(${tag_width}x$height)^fg()"
elif [[ "${TAGS2[@]}" == *"+${i:1}"* ]]; then
echo -n "^bg($locolor)^fg(#000000) ${i:1} ^fg()^bg()"
# echo -n "^fg($locolor)^ro(${tag_width}x$height)^fg()"
else
case ${i:0:1} in
'#')
echo -n "^bg($selcolor)^fg(#000000) ${i:1} ^fg()^bg()"
# echo -n "^fg($selcolor)^ro(${tag_width}x$height)^fg()"
;;
'+')
echo -n "^bg($locolor)^fg(#000000) ${i:1} ^fg()^bg()"
# echo -n "^fg($locolor)^ro(${tag_width}x$height)^fg()"
;;
':')
echo -n "^bg($hicolor)^fg(#000000) ${i:1} ^fg()^bg()"
# echo -n "^fg($hicolor)^ro(${tag_width}x$height)^fg()"
;;
'!')
echo -n "^bg($urcolor)^fg(#000000) ${i:1} ^fg()^bg()"
# echo -n "^fg($urcolor)^ro(${tag_width}x$height)^fg()"
;;
*)
echo -n "^bg($bgcolor)^fg(#ffffff) ${i:1} ^fg()^bg()"
# echo -n "^bg()^fg($bgcolor)^ro(${tag_width}x$height)^fg()"
;;
esac
fi
echo -n "$separator"
done
}
function print_mailboxes() {
declare -A mailnames
2012-02-06 22:28:14 +01:00
mailboxes=(ninthfloor gmail arch aethon ryuslash.org)
2012-03-20 17:01:26 +01:00
mailnames=([ninthfloor]="9f" [gmail]="gm" [aethon]="aet" [ryuslash.org]="ryu")
2012-02-06 22:28:14 +01:00
mailtxt=""
for j in "${mailboxes[@]}"; do
2012-03-20 17:01:26 +01:00
mailfile="$HOME/documents/mail/$j/inbox/new/"
2012-02-06 22:28:14 +01:00
mailcnt=$(ls $mailfile | wc -l)
if [ $mailcnt -gt 0 ]; then
mailsha1=$(echo $j | sha1sum)
mailcolor="#${mailsha1:0:6}"
else
mailcolor=$bgcolor
fi
mailtxt="$mailtxt${separator}^bg($mailcolor)^fg(#ffffff) ${mailnames[$j]} ^fg()^bg()"
2012-02-06 22:28:14 +01:00
# echo -n "^fg($mailcolor)^ro(${tag_width}x$height)^fg()$separator"
done
mailtxt_only=$(echo -n "$mailtxt" | sed 's.\^[^(]*([^)]*)..g')
let mailtxt_width=$(textwidth "$font" "$mailtxt_only")+20
echo -n "^p(_RIGHT)^p(-$mailtxt_width)$mailtxt"
}
function print_services() {
2012-02-06 23:56:33 +01:00
services=(emacs dunst xbindkeys sshd)
2012-02-06 22:28:14 +01:00
servicetxt=""
for j in "${services[@]}"; do
servicetxt="$servicetxt$separator$(status $j)"
done
servicetxt_only=$(echo -n "$servicetxt" | sed 's.\^[^(]*([^)]*)..g')
2012-02-09 09:14:01 +01:00
let servicetxt_width=($(textwidth "$font" "$servicetxt_only")+7)/2
2012-02-06 22:28:14 +01:00
echo -n "^p(_CENTER)^p(-$servicetxt_width)$servicetxt"
}
function status()
{
running=$(${1}_running 2>/dev/null || pidof $1)
if [ -n "$running" ]; then
color="darkgreen"
else
color="darkred"
fi
echo -n "^bg($color)^fg(#ffffff) $1 ^fg()^bg()"
}
function emacs_running()
{
ps ax | awk '{ print $5 " " $6 }' | grep -E "^emacs --daemon"
}
2012-01-31 16:03:40 +01:00
herbstclient pad $monitor -5 -5 $(expr -5 + $height) -5
herbstclient pad $monitor2 -5 -5 -5 -5
{
childpid=$!
herbstclient --idle
kill $childpid
} 2> /dev/null | {
TAGS=( $(herbstclient tag_status $monitor) )
TAGS2=( $(herbstclient tag_status $monitor2) )
while true ; do
separator="^fg($bgcolor)^ro(1x$height)^fg()"
2012-02-06 22:28:14 +01:00
print_tags
print_services
print_mailboxes
echo
# wait for next event
read line || break
cmd=( $line )
# find out event origin
case "${cmd[0]}" in
tag*)
#echo "reseting tags" >&2
TAGS=( $(herbstclient tag_status $monitor) )
TAGS2=( $(herbstclient tag_status $monitor2) )
;;
quit_panel)
exit
;;
esac
done
} 2> /dev/null | dzen2 -w $width -x $x -y $y -fn "$font" -h $height \
-ta l -bg "$bgcolor"
2012-02-09 09:14:01 +01:00
# Local Variables:
# eval: (git-auto-commit-mode 1)
# End: