summaryrefslogtreecommitdiffstats
path: root/.config/herbstluftwm/panel.sh
blob: bdc7eaa1992ccac837b6e5e05e47e6a04d5571aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/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="-*-tamsyn-medium-r-*-*-14-*-*-*-*-*-*-*"
fgcolor='#eeeeec'
bgcolor='#252a2b'
hintcolor="#0c191c"

function uniq_linebuffered() {
    awk '$0 != l { print ; l=$0 ; fflush(); }' "$@"
}

herbstclient pad $monitor $height
{
    # events:
    #mpc idleloop player &
    while true ; do
        date +'date ^fg($fgcolor)%H:%M^fg(#909090), %Y-%m-^fg($fgcolor)%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"
        separator="^fg(#141414)^ro(1x$height)^fg()"
        # draw tags
        echo -n "$separator"
        for i in "${TAGS[@]}" ; do
            case ${i:0:1} in
                '#')
                    echo -n "^bg(#0c191c)^fg(#eeeeec)"
                    ;;
                '+')
                    echo -n "^bg(#2e3436)^fg(#555753)"
                    ;;
                ':')
                    echo -n "^bg(#2e3436)^fg($fgcolor)"
                    ;;
                '!')
                    echo -n "^bg(#a40000)^fg(#edd400)"
                    ;;
                *)
                    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 "$fgcolor"