Re: [wmii] next and previous tag

From: Timo Benk <timo.benk_AT_gmx.de>
Date: Sat, 10 Feb 2007 10:38:00 +0100

Mirco Geremia wrote:
> Hi!
> i was looking for something for jump to next (and previous) tag; i found this
>
> $MODKEY-n)
> seltag="`wmiir read /tag/sel/ctl 2>/dev/null`";
> xwrite /ctl view `wmiir ls /tag | awk "/$seltag/ {getline; print}"`;;
>
> but there's a problem: in /tag ther's also sel/ directory, and when $seltag becomes "sel" there are two sel/ dirs, and the script finds the the first sending /ctl view to the second sel.
>
> ehm, i don't know if the problem (read "my english") is clear..
>
> any ideas?
>
> ola ;)
> mirco
>
Maybe a bit complex, but it works for me (together with detaching/attaching).

Take a look into the $MODKEY-comma, $MODKEY-period, $MODKEY-d and
$MODKEY-a sections.

Greetings,
-timo

-- 
Timo Benk - Jabber ID: fry_AT_downtempo.de - ICQ ID: #414944731
PGP Public Key: http://m28s01.vlinux.de/timo_benk_gpg_key.asc

#!/bin/bash
# configure wmii

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 () {
        if [ -n "$1" ]
        then
                prog=$1; shift
                echo `PATH="$WMII_CONFPATH:$PATH" which $prog` "$@"
        fi
}

tagsmenu() {
        tag=`wmiir read /tag/sel/ctl`
        tags=`wmiir ls /tag | sed 's,/,,; /^sel$/d' | awk "BEGIN{print \"$tag\"} !/^$tag\$/" | $DMENU`
        test -n "$tags" && xwrite $@ "$tags"
}

pid_of_cur_window ()
{
    X11ID=`wmiir read /client/sel/ctl`
    HEX_X11ID="0x`gbase -s -d $X11ID | grep Hex | cut -f2 -d' '`"
    x11id2pid $HEX_X11ID | grep pid | cut -d= -f2 | sed 's/ //g'
}

MODKEY=Mod1
UP=Up
DOWN=Down
LEFT=Left
RIGHT=Right

WMII_FONT='-*-snap.de-*-*-*-*-*-*-75-75-*-*-*-*'
#WMII_FONT='-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*'
# colors are text, bg, border
WMII_NORMCOLORS='#222222 #eeeeee #666666'
WMII_SELCOLORS='#444444 #bbbbbb #556088'
WMII_FOCUSCOLORS='#ffffff #335577 #447799'
WMII_BACKGROUND='#333333'

DMENU="dmenu -b -fn $WMII_FONT -nb #eeeeee -nf #222222 -sb #335577 -sf #ffffff"
WMII_TERM="xterm"

export DMENU WMII_FONT WMII_FOCUSCOLORS WMII_SELCOLORS WMII_NORMCOLORS WMII_TERM

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

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

# COLUMN RULES
wmiir write /colrules <<EOF
/1/ -> 50+50
EOF

# TAGGING RULES
wmiir write /tagrules <<EOF
/XMMS.*/ -> ~
/Gimp.*/ -> ~
/MPlayer.*/ -> ~
/Grsync:grsync/ -> ~
/Toplevel:openDialog.*/ -> ~
/Toplevel:preferencesDialog.*/ -> ~
/Toplevel:passPolicyDialog.*/ -> ~
/Toplevel:dbPrefsDialog.*/ -> ~
/Toplevel:passwordDialog-0.*/ -> ~
/Gnome-terminal:gnome-terminal/ -> xterm
/rdesktop:rdesktop:rdesktop/ -> xen
/com-ca-directory-jxplorer-JXplorer:sun-awt-X11-XFramePeer/ -> office
/VendorShell:AWTapp/ -> office
/com-zerog-lax-LAX:sun-awt-X11-XFramePeer/ -> office
/com.ca.directory.jxplorer.JXplorer:com.ca.directory.jxplorer.JXplorer/ -> office
/Wine:OUTLOOK.EXE/ -> office
/Wine:IEXPLORE.EXE/ -> web
/Gaim:gaim:gaim/ -> ~+gaim
/Gaim:gaim:Plugins/ -> ~+gaim
/Gaim:gaim:Accounts/ -> ~+gaim
/Gaim:gaim:About Gaim/ -> ~+gaim
/Gaim:gaim:Gaim-Encryption Key Received/ -> ~+gaim
/Gaim:gaim:Buddy Information/ -> ~+gaim
/Gaim:gaim/ -> gaim
/Firefox-bin:Gecko/ -> web
/Thunderbird-bin:Gecko/ -> web
/MyPasswordSafe:MyPasswordSafe/ -> web
/Vmware-server-console:vmware-server-console/ -> vmware
/SmartSVN:smartsvn.pJ.*/ -> ~
/SmartSVN:smartsvn.pH:.*/ -> ~
/moneyplex:unnamed:moneyplex 2007/ -> moneyplex
/moneyplex:unnamed:Mandant/ -> ~+moneyplex
/moneyplex:unnamed:moneyplex$/ -> ~
/moneyplex:unnamed:Bitte/ -> ~
/Sylpheed:main_window/ -> web
/Fireglcontrolpanel:fireglcontrolpanel:ATI Control Panel/ -> ~
/com.ca.directory.jxplorer.JXplorer:javax.swing.JWindow/ -> ~
/freemind.main.FreeMindStarter:freemind.main.FreeMindSplash:FreeMind/ -> ~
/freemind-main-FreeMindStarter:sun-awt-X11-XFramePeer/ -> ~
/.*/ -> !
/.*/ -> 1
EOF

# MISC
xsetroot -solid $WMII_BACKGROUND
OLD_STATUS_PID=`ps -ef | grep /home/timo/.wmii-3.5/lib/status | grep -v grep | awk '{print $2}'`
if test -n "$OLD_STATUS_PID"
then
    for PID in $OLD_STATUS_PID
    do
        kill -9 $PID
    done
fi
nice -n19 /home/timo/.wmii-3.5/lib/status &
PROGS_FILE="$WMII_NS_DIR/.dmenu.proglist"
ACTIONS_DIRS=`echo "$WMII_CONFPATH" | tr : ' '`
proglist `echo "$PATH" | tr : ' '` >$PROGS_FILE &

# SHORTCUTS
wmiir write /keys <<EOF
$MODKEY-$LEFT
$MODKEY-$RIGHT
$MODKEY-$DOWN
$MODKEY-$UP
$MODKEY-space
$MODKEY-period
$MODKEY-comma
$MODKEY-Tab
$MODKEY-d
$MODKEY-c
$MODKEY-f
$MODKEY-s
$MODKEY-m
$MODKEY-q
$MODKEY-a
$MODKEY-p
$MODKEY-n
$MODKEY-k
$MODKEY-j
$MODKEY-t
$MODKEY-0
$MODKEY-1
$MODKEY-2
$MODKEY-3
$MODKEY-4
$MODKEY-5
$MODKEY-6
$MODKEY-7
$MODKEY-8
$MODKEY-9
$MODKEY-Return
$MODKEY-Shift-$LEFT
$MODKEY-Shift-$RIGHT
$MODKEY-Shift-$UP
$MODKEY-Shift-$DOWN
$MODKEY-Shift-space
$MODKEY-Shift-r
$MODKEY-Shift-c
$MODKEY-Shift-k
$MODKEY-Shift-d
$MODKEY-Shift-m
$MODKEY-Shift-s
$MODKEY-Shift-t
$MODKEY-Shift-0
$MODKEY-Shift-1
$MODKEY-Shift-2
$MODKEY-Shift-3
$MODKEY-Shift-4
$MODKEY-Shift-5
$MODKEY-Shift-6
$MODKEY-Shift-7
$MODKEY-Shift-8
$MODKEY-Shift-9
EOF

# TAG BAR
wmiir ls /lbar |
while read bar
do
        wmiir remove "/lbar/$bar"
done

seltag="`wmiir read /tag/sel/ctl 2>/dev/null`"
wmiir ls /tag | sed -e 's,/$,,; /^sel$/d' |
while read tag
do
        if [ "X$tag" = "X$seltag" ]; then
                echo "$WMII_FOCUSCOLORS" "$tag" | wmiir create "/lbar/$tag"
        else
                echo "$WMII_NORMCOLORS" "$tag" | wmiir create "/lbar/$tag"
        fi
done

xset m 6/1

# EVENT LOOP
wmiir read /event 2>/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;;
        CreateClient)
        /home/timo/.wmii-3.5/lib/toggle "$parms" &
        ;;
        CreateTag)
                echo "$WMII_NORMCOLORS" "$parms" | wmiir create "/lbar/$parms"
        xwrite /tag/$parms/ctl colmode sel max
                ;;
        DestroyTag)
                wmiir remove "/lbar/$parms"
                ;;
        FocusTag)
                xwrite "/lbar/$parms" "$WMII_FOCUSCOLORS" "$parms"
                ;;
        UnfocusTag)
                xwrite "/lbar/$parms" "$WMII_NORMCOLORS" "$parms"
                ;;
        LeftBarClick)
                shift
                xwrite /ctl view "$@";;
        Key)
                case "$1" in
        $MODKEY-comma)
            CUR=`wmiir read /tag/sel/ctl`

            EXCLUDE='_'
            if test "$EXCLUDE" = "`echo "$CUR" | grep "$EXCLUDE" | cut -c1`"
            then
                PREV=`wmiir ls /tag | egrep -v '^sel/' | sed 's/\///' | grep -B1 "$CUR" | head -n1`
            else
                PREV=`wmiir ls /tag | egrep -v '^sel/' | sed 's/\///' | grep -v "$EXCLUDE" | grep -B1 "$CUR" | head -n1`
            fi

            if test "$PREV" = "$CUR"
            then
                PREV=`wmiir ls /tag | egrep -v '^sel/' | sed 's/\///' | grep -v "$EXCLUDE" | tail -n1`
            fi

            if test -n "$PREV"
            then
                xwrite /ctl "view $PREV"
            fi;;
        $MODKEY-period)
            CUR=`wmiir read /tag/sel/ctl`

            EXCLUDE='_'
            if test "$EXCLUDE" = "`echo "$CUR" | grep "$EXCLUDE" | cut -c1`"
            then
                NEXT=`wmiir ls /tag | egrep -v '^sel/' | sed 's/\///' | grep -A1 "$CUR" | tail -n1`
            else
                NEXT=`wmiir ls /tag | egrep -v '^sel/' | sed 's/\///' | grep -v "$EXCLUDE" | grep -A1 "$CUR" | tail -n1`
            fi

            if test "$NEXT" = "$CUR"
            then
                NEXT=`wmiir ls /tag | egrep -v '^sel/' | sed 's/\///' | grep -v "$EXCLUDE" | head -n1`
            fi

            if test -n "$NEXT"
            then
                xwrite /ctl "view $NEXT"
            fi;;
        $MODKEY-d)
            PROPS=`wmiir read /client/sel/props`
            if test -z "`wmiir read /client/sel/tags | grep '_'`"
            then
                export DETACHED="`wmiir read /tag/sel/index | grep "$PROPS" | awk '{print $2}'` $DETACHED"
                xwrite /client/sel/tags '_'

                if test "`wmiir read /client/sel/tags | cut -c1`" = '_'
                then
                    LAST_TAG=`wmiir ls /tag | grep -v 'sel/' | sed 's/\///' | tail -n2 | head -n1`
                    xwrite /ctl "view $LAST_TAG"
                fi
            fi;;
        $MODKEY-a)
            if test -z "`wmiir read /client/sel/tags | grep '_'`"
            then
                ATTACHED=""
                while test -z "$ATTACHED" && test -n "`echo $DETACHED | awk '{print $1}'`"
                do
                    IDX=`echo $DETACHED | awk '{print $1}'`
                    if test -n "`wmiir read /client/$IDX/tags | grep '_' | cut -c1`"
                    then
                        CUR=`wmiir read /tag/sel/ctl`
                        xwrite /client/$IDX/tags $CUR
                        ATTACHED="y"
                    fi
                    DETACHED=`echo $DETACHED | sed 's/^ *[^ ]* *//'`
                done
            fi;;
                $MODKEY-q)
            ANSWER="`(echo quit;echo shutdown;echo reboot) | dmenu -b`"
            if test "$ANSWER" = "quit"
            then
                killall -9 .xsession
            elif test "$ANSWER" = "shutdown"
            then
                sudo halt
                xwrite /ctl quit
            elif test "$ANSWER" = "reboot"
            then
                sudo reboot
                xwrite /ctl quit
            fi;;
        $MODKEY-Shift-k)
            RET=`echo -en "kill\nabort" | dmenu -b`
            if test "$RET" = "kill"
            then
                X11ID=`wmiir read /client/sel/ctl`
                kill -9 `x11id2pid $X11ID`
            fi;;
        $MODKEY-Shift-r)
            /home/timo/.wmii-3.5/wmiirc;;
                $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-k)
                        xwrite /tag/sel/ctl select down;;
                $MODKEY-j)
                        xwrite /tag/sel/ctl select up;;
                $MODKEY-space)
                        xwrite /tag/sel/ctl select toggle;;
                $MODKEY-Shift-d)
                        xwrite /tag/sel/ctl colmode sel default;;
                $MODKEY-Shift-s)
                        xwrite /tag/sel/ctl colmode sel stack;;
                $MODKEY-Shift-m)
                        xwrite /tag/sel/ctl colmode sel max;;
                $MODKEY-f)
                        xwrite /tag/sel/0/sel/geom 0 0 0 0;;
                $MODKEY-c)
            xwrite /client/sel/ctl kill;;
                $MODKEY-p)
                        sh -c "`$DMENU <$PROGS_FILE`" &;;
                $MODKEY-n)
            TAG=`cat /home/timo/.wmii-3.5/.tags | dmenu -b`
            echo view $TAG | wmiir write /ctl;;
                $MODKEY-t)
            TAG=`(cat /home/timo/.wmii-3.5/.tags; wmiir ls /tag | grep -v "sel/" | sed 's/\///') | sort | uniq | dmenu -b`
            echo $TAG | wmiir write /client/sel/tags
            echo view $TAG | wmiir write /ctl;;
                $MODKEY-Shift-t)
            TAG=`wmiir ls /tag | grep -v "sel/" | sed 's/\///' | dmenu -b`
            echo view $TAG | wmiir write /ctl;;
                $MODKEY-[0-9])
                        xwrite /ctl view "`echo $1 | sed 's/.*-//'`";;
                $MODKEY-Return)
                        gnome-terminal --hide-menubar -e screen.sh &;;
                $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-Tab)
            /home/timo/.wmii-3.5/lib/tab_switch.sh;;
                $MODKEY-Shift-[0-9])
                        xwrite /client/sel/tags "`echo $1 | sed 's/.*-//'`";;
                esac;;
        esac
done &
Received on Sat Feb 10 2007 - 10:38:18 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 16:20:41 UTC