#!/bin/bash
# configure wmii
#killall gnome-keyring-daemon
#export $(eval gnome-keyring-daemon)
eval $(ssh-agent)
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' | $DMENU \
| sed 's/^\.\.\?$//; s/^\.\.\?+//g; s/+\.\.\?$//g; s/+\.\.\?+/+/g; s/\W//'`
test -n "$tags" && xwrite $@ "$tags"
}
MODKEY=Mod1
WINKEY=Mod4
UP=k
DOWN=j
LEFT=h
RIGHT=l
WMII_FONT='-xos4-terminus-medium-r-*-*-*-140-*-*-c-*-iso10646-1'
# colors are text, bg, border
#WMII_NORMCOLORS='#222222 #eeeeee #6666aa'
#WMII_SELCOLORS='#444444 #bbbbbb #006088'
#WMII_FOCUSCOLORS='#ffffff #335577 #447700'
#WMII_BACKGROUND='#333333'
#
WMII_FOCUSCOLORS='#ffffff #153F1F #2A7F3F'
WMII_BACKGROUND='#333333'
#WMII_NORMCOLORS='#222222 #5FBF77 #2A7F3F'
WMII_NORMCOLORS='#e0e0e0 #444444 #666666'
DMENU="dmenu -b -fn $WMII_FONT -nb #444444 -nf #e0e0e0 -sb #2A7F3F -sf #ffffff"
WMII_TERM="urxvt" # "
wmii_ssh () {
pgrep -f urxvt-$1 &>/dev/null || $WMII_TERM --title urxvt-$1 -e ssh $1 &
xwrite /ctl view $1
}
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
/gajim/ -> 20+80
EOF
# TAGGING RULES
wmiir write /tagrules <<EOF
/Gimp.*/ -> gimp
/MPlayer.*/ -> ~
/.*Gajim.*/ -> gajim
/.*Bon Echo.*/ -> ff
/.*Mozilla Firefox .*/ -> ff
/.Minefield.*/ -> ff
/.Iceweasel.*/ -> ff
/urxvt-lightmare/ -> local
/urxvt-castle/ -> castle
/urxvt-honti/ -> honti
/urxvt-msandbox/ -> msandbox
/urxvt-ming/ -> ming
/urxvt-pda/ -> pda
/wmii-mpc/ -> music
/wmii-tail/ -> log
/.*/ -> !
/.*/ -> 1
EOF
# MISC
xsetroot -solid $WMII_BACKGROUND
`conf_which 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-d
$MODKEY-f
$MODKEY-s
$MODKEY-m
$MODKEY-a
$MODKEY-p
$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-c
$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
$WINKEY-Return
$WINKEY-l
$WINKEY-Shift-l
$WINKEY-Shift-m
$WINKEY-c
$WINKEY-h
$WINKEY-g
$WINKEY-b
$WINKEY-m
$WINKEY-f
$WINKEY-s
$WINKEY-i
$WINKEY-p
$WINKEY-o
EOF
#$WINKEY-Shift-f
# 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
# 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;;
#ClientFocus)
# if (wmiir read /client/$parms/tags | grep -q gajim)
# then
# xwrite /lbar/gajim gajim
# fi
#;;
UrgentTag)
if [ "$parms" = "Client gajim" ]; then
xwrite /lbar/gajim '#222222 #ff00aa #6666aa *gajim'
fi
;;
NotUrgentTag)
if [ "$parms" = "Client gajim" ]; then
xwrite /lbar/gajim 'gajim'
fi
;;
CreateClient)
#&& \
# (! wmiir read /tag/gajim/ctl | grep 'colmode 2' -q)
if (wmiir read /client/$parms/props | grep 'gajim.py:Gajim.py:' -q) && \
(wmiir read /tag/gajim/ctl | grep -q 'select 1')
then
echo gajim
xwrite /tag/sel/ctl send $parms right
xwrite /tag/sel/ctl select $parms
xwrite /tag/gajim/ctl 'colmode 2 stack'
fi
;;
CreateTag)
echo "$WMII_NORMCOLORS" "$parms" | wmiir create "/lbar/$parms"
;;
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-$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-d)
xwrite /tag/sel/ctl colmode sel default;;
$MODKEY-s)
echo s
xwrite /tag/sel/ctl colmode sel stack;;
$MODKEY-m)
xwrite /tag/sel/ctl colmode sel max;;
$MODKEY-f)
xwrite /tag/sel/0/sel/geom 0 0 0 0;;
$MODKEY-a)
`conf_which "\`proglist $ACTIONS_DIRS | $DMENU\`"` &;;
$MODKEY-p)
sh -c "`$DMENU <$PROGS_FILE`" &;;
$MODKEY-t)
tagsmenu /ctl view &;;
$MODKEY-[0-9])
xwrite /ctl view "`echo $1 | sed 's/.*-//'`";;
$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)
tagsmenu "/client/`wmiir read /client/sel/ctl`/tags" &;;
$MODKEY-Shift-[0-9])
xwrite /client/sel/tags "`echo $1 | sed 's/.*-//'`";;
$WINKEY-g)
pgrep -f gajim &>/dev/null || gajim&>/dev/null&
xwrite /ctl view gajim
;;
# local term
$MODKEY-Return|$WINKEY-l)
unset STY
pgrep -f urxvt-lightmare &>/dev/null || $WMII_TERM --title urxvt-lightmare -e screen -xRR &
xwrite /ctl view local
;;
$WINKEY-c) wmii_ssh castle ;;
$WINKEY-h) wmii_ssh honti ;;
$WINKEY-b) wmii_ssh msandbox ;;
$WINKEY-m) wmii_ssh ming ;;
$WINKEY-p) wmii_ssh pda ;;
$WINKEY-o) wmii_ssh lifebook ;;
$WINKEY-Shift-l) pgrep -f wmii-tail &>/dev/null|| $WMII_TERM --title \
wmii-tail -e tail -f /var/log/messages.log &
xwrite /ctl view log
;;
$WINKEY-Shift-m) pgrep -f wmii-mpc &>/dev/null|| $WMII_TERM --title \
wmii-mpc -e sh -c '. ~/.mpdenv; ncmpc -C' &
xwrite /ctl view music
;;
$WINKEY-f)
pgrep firefox &>/dev/null|| iceweasel&>/dev/null&
xwrite /ctl view ff
;;
$WINKEY-i) xwrite /ctl view internet ;;
esac;;
esac
done &