From ea07fd093bae2cccb65ccf2386ea0882b16f7c96 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Thu, 10 Nov 2011 01:06:17 +0100 Subject: [PATCH] HERBSTLUFTWM: Show mail counts in panel --- .config/herbstluftwm/autostart | 2 +- .config/herbstluftwm/panel.sh | 94 ++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 .config/herbstluftwm/panel.sh diff --git a/.config/herbstluftwm/autostart b/.config/herbstluftwm/autostart index 767ff36..df0ed6f 100755 --- a/.config/herbstluftwm/autostart +++ b/.config/herbstluftwm/autostart @@ -111,4 +111,4 @@ ;; Show panel -(system "/etc/xdg/herbstluftwm/panel.sh &") +(system "~/.config/herbstluftwm/panel.sh &") diff --git a/.config/herbstluftwm/panel.sh b/.config/herbstluftwm/panel.sh new file mode 100755 index 0000000..1b11845 --- /dev/null +++ b/.config/herbstluftwm/panel.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +monitor=${1:-0} +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]} +y=${geometry[1]} +width=${geometry[2]} +height=16 +font="-*-fixed-medium-*-*-*-12-*-*-*-*-*-*-*" +bgcolor='#3E2600' + +function uniq_linebuffered() { + awk '$0 != l { print ; l=$0 ; fflush(); }' "$@" +} + +herbstclient pad $monitor $height +{ + # events: + #mpc idleloop player & + while true ; do + date +'date ^fg(#efefef)%H:%M^fg(#909090), %Y-%m-^fg(#efefef)%d' + sleep 1 || break + done > >(uniq_linebuffered) & + childpid=$! + herbstclient --idle + kill $childpid +} 2> /dev/null | { + TAGS=( $(herbstclient tag_status $monitor) ) + date="" + while true ; do + bordercolor="#26221C" + hintcolor="#573500" + separator="^fg(#141414)^ro(1x$height)^fg()" + # draw tags + for i in "${TAGS[@]}" ; do + case ${i:0:1} in + '#') + echo -n "^bg(#9fbc00)^fg(#141414)" + ;; + '+') + echo -n "^bg(#9CA668)^fg(#141414)" + ;; + ':') + echo -n "^bg(#6A4100)^fg(#141414)" + ;; + '!') + echo -n "^bg(#FF0675)^fg(#141414)" + ;; + *) + echo -n "^bg()^fg()" + ;; + esac + echo -n " ${i:1} " + echo -n "$separator" + done + echo -n "^bg()^p(_CENTER)" + # small adjustments + nfmail=`ls ~/documents/mail/ninthfloor/INBOX/new/ | wc -l` + gmail=`ls ~/documents/mail/gmail/INBOX/new/ | wc -l` + archmail=`ls ~/documents/mail/arch/INBOX/new/ | wc -l` + aethonmail=`ls ~/documents/mail/aethon/INBOX/new/ | wc -l` + right="$separator 9f: $nfmail $separator gmail: $gmail $separator arch: $archmail $separator aethon: $aethonmail $separator^bg($hintcolor) $date $separator" + right_text_only=$(echo -n "$right"|sed 's.\^[^(]*([^)]*)..g') + # get width of right aligned text.. and add some space.. + width=$(textwidth "$font" "$right_text_only ") + echo -n "^p(_RIGHT)^p(-$width)$right" + 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) ) + ;; + date) + #echo "reseting date" >&2 + date="${cmd[@]:1}" + ;; + quit_panel) + exit + ;; + #player) + # ;; + esac + done +} 2> /dev/null | dzen2 -w $width -x $x -y $y -fn "$font" -h $height \ + -ta l -bg "$bgcolor" -fg '#efefef'