rndm_luser /.wmii-3.5/wmiirc

Added a function to jump to a client in an arbitrary view, and a clickable lbar tag which showed/cycled layouts. The Gentoo distribution comes with a wmiirc with a more efficient event loop, so this is no longer used.
#!/bin/sh
# .wmii-3.5/wmiirc
# $Id$

# FUNCTIONS {{{1
xwrite()
{
        file="$1"; shift
        echo -n "$@" | wmiir write "$file"
}

proglist()
{
        ls -lL "$@" 2>/dev/null | awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq
}

conf_which()
{
        prog=$1; shift

        if [ -n "$prog" ]; then
                echo `PATH="$WMII_CONFPATH:$PATH:" which $prog` "$@"
        fi
}

tagsmenu()
{
        tag=`wmiir read /tag/sel/ctl`
        wmiir ls /tag | sed "s|/||; /^sel\$/d" | $DMENU
}

clientsmenu()
{
        sel=$(for ctl in `wmiir ls /client | sed -e 's|/||; /sel/d'`; do
        echo "`wmiir read /client/$ctl/tags` $ctl `wmiir read /client/$ctl/label`"
        done | $DMENU)

        if [ -n "$sel" ]; then
                xwrite /ctl "view ${sel%% *}"
                sel=${sel#* }
                xwrite "/tag/sel/ctl" "select client ${sel%% *}"
        fi
}


# CONFIGURATION VARIABLES {{{1
MODKEY=Mod1
UP=k
DOWN=j
LEFT=h
RIGHT=l

WMII_FONT='-*-*-medium-r-semicondensed-*-13-*-*-*-*-*-iso10646-1'
#WMII_FONT='-*-profont-*-*-*-*-15-*-*-*-*-*-*-*'

# Colors tuples are "  "

#WMII_FOCUSCOLORS='#4fff00 #418302 #4fff00'
#WMII_NORMCOLORS='#4f9f00 #1c3a01 #4f9f00'
#WMII_SELCOLORS=$WMII_FOCUSCOLORS
#WMII_BACKGROUND='#000000'
#DMENU="dmenu -fn $WMII_FONT -nb #1c3a01 -nf #ffffff -sb #418302 -sf #ffffff"

WMII_FOCUSCOLORS='#ffffff #285577 #4c7899'
WMII_SELCOLORS=$WMII_FOCUSCOLORS
WMII_NORMCOLORS='#888888 #222222 #333333'
WMII_BACKGROUND='#222222'
DMENU="dmenu -fn $WMII_FONT -nb #222222 -nf #888888 -sb #285577 -sf #ffffff"

#WMII_FOCUSCOLORS='#ffffff #153f1f #2a7f3f'
#WMII_SELCOLORS=$WMII_FOCUSCOLORS
#WMII_BACKGROUND='#666666'
#WMII_NORMCOLORS='#222222 #5fbf77 #2a7f3f' 
#DMENU="dmenu -b -fn $WMII_FONT -nb #5fbf77 -nf #222222 -sb #153f1f -sf #ffffff"

WMII_TERM="uxterm"

export DMENU WMII_FONT WMII_FOCUSCOLORS WMII_SELCOLORS WMII_NORMCOLORS WMII_TERM 

# WM CONFIGURATION {{{1
wmiir write /ctl << EOF
font $WMII_FONT
focuscolors $WMII_FOCUSCOLORS
selcolors $WMII_SELCOLORS
normcolors $WMII_NORMCOLORS
grabmod $MODKEY
border 1
EOF

# COLUMN RULES {{{1
wmiir write /colrules < 58+42
EOF

# TAGGING RULES {{{1
wmiir write /tagrules < ~
/XMMS.*/ -> ~
/Gimp.*/ -> gimp
/MPlayer.*/ -> ~
/Firefox/ -> www
/xload/ -> ~
/xclock/ -> ~
/xnetload/ -> ~
/xbiff/ -> ~
/sunclock/ -> ~
/.*/ -> !
/.*/ -> 1
EOF

# MISC {{{1
PROGS_FILE="$WMII_NS_DIR/.dmenu.proglist"
ACTIONS_DIRS=`echo "$WMII_CONFPATH" | tr : ' '`

`conf_which status` &
xsetroot -solid "$WMII_BACKGROUND"
proglist `echo "$PATH" | tr : ' '` >$PROGS_FILE &

# Stop any running instances of wmiirc
echo Start wmiirc | wmiir write /event || exit 1

# BOUND KEYS {{{1
wmiir write /keys </dev/null |
while read event; do
        set -f
        set -- $event
        set +f
        type="$1"; shift
        parms="$@"
        case "$type" in
        Start)
                if test "$1" = "wmiirc"; then
                        exit
                fi;;
        CreateTag)
                echo "$WMII_NORMCOLORS" "$parms" | wmiir create "/lbar/$parms"
                update_layout_tag
                ;;
        DestroyTag)
                wmiir remove "/lbar/$parms"
                ;;
        FocusTag)
                xwrite "/lbar/$parms" "$WMII_FOCUSCOLORS" "$parms"
                update_layout_tag
                ;;
        UnfocusTag)
                xwrite "/lbar/$parms" "$WMII_NORMCOLORS" "$parms"
                ;;
        LeftBarClick)
                shift
                if [ "$@" == $layouttag ]; then
                        case "`get_colmode`" in
                        default)
                                xwrite /tag/sel/ctl colmode sel stack;;
                        stack)
                                xwrite /tag/sel/ctl colmode sel max;;
                        max)
                                xwrite /tag/sel/ctl colmode sel default;;
                        esac
                        update_layout_tag
                else
                        xwrite /ctl view "$@"
                fi;;
        Key)
                key="$1"
                case "$key" in
                $MODKEY-$LEFT)
                        xwrite /tag/sel/ctl select left;;
                $MODKEY-$RIGHT)
                        xwrite /tag/sel/ctl select right;;
                $MODKEY-$DOWN)
                        xwrite /tag/sel/ctl select down;;
                $MODKEY-$UP)
                        xwrite /tag/sel/ctl select up;;
                $MODKEY-space)
                        xwrite /tag/sel/ctl select toggle;;
                $MODKEY-b)
                        warp;;
                $MODKEY-d)
                        xwrite /tag/sel/ctl colmode sel default
                        update_layout_tag;;
                $MODKEY-s)
                        xwrite /tag/sel/ctl colmode sel stack
                        update_layout_tag;;
                $MODKEY-m)
                        xwrite /tag/sel/ctl colmode sel max
                        update_layout_tag;;
                $MODKEY-a)
                        `conf_which "$(proglist $ACTIONS_DIRS | $DMENU)"` &;;
                $MODKEY-p)
                        sh -c "`$DMENU <$PROGS_FILE`" &;;
                $MODKEY-t)
                        xwrite /ctl "view `tagsmenu`" &;;
                $MODKEY-w)
                        clientsmenu;;
                $MODKEY-[0-9])
                        xwrite /ctl view "`echo $key | sed 's/.*-//'`"
                        update_layout_tag;;
                $MODKEY-Return)
                        $WMII_TERM &;;
                $MODKEY-Shift-$LEFT)
                        xwrite /tag/sel/ctl send sel left;;
                $MODKEY-Shift-$RIGHT)
                        xwrite /tag/sel/ctl send sel right;;
                $MODKEY-Shift-$DOWN)
                        xwrite /tag/sel/ctl send sel down;;
                $MODKEY-Shift-$UP)
                        xwrite /tag/sel/ctl send sel up;;
                $MODKEY-Shift-space)
                        xwrite /tag/sel/ctl send sel toggle;;
                $MODKEY-Shift-c)
                        xwrite /client/sel/ctl kill;;
                $MODKEY-Shift-t)
                        xwrite "/client/`wmiir read /client/sel/ctl`/tags" "`tagsmenu`" &;;
                $MODKEY-Shift-[0-9])
                        xwrite /client/sel/tags "`echo $key | sed 's/.*-//'`";;
                esac;;
        esac
done &