You can make this a bit simpler, assuming I understand it correctly:
#!/bin/sh
set -f
if [ -n "$1" ]; then
DISPLAY=":0.$1"
else
if [ $DISPLAY == ":0.0" ]; then
DISPLAY=":0.1"
else
DISPLAY=":0.0"
fi
fi
export WMII_ADDRESS="unix!/tmp/ns.$USER.${DISPLAY%.0}/wmii"
if [ $(wmiir ls /client | grep -v '^sel/$' | wc -l) -eq "0" ];
then
# no clients open, just warp to upper left corner
swarp 50 50
else
client=$(wmiir -a $address read /client/sel/ctl | sed 1q) # sed 1q will be
needed in the future
set -- $(wmiir -a $address read /tag/sel/index | awk '$2 == "'$client'"')
col=$1
if [ $col = '~' ]; then
x=$3
y=$4
else
y=$3
x=$(wmiir read /tag/sel/index | awk '/^# '$col' / { print $3 }')
fi
swarp $(($x+5)) $(($y+5)) # $(()) is valid in POSIX sh, $[] is not
fi
"Beware of bugs in the above code..."
--
Kris Maglione
The higher the level of prestige accorded the people
behind the plan, the least less chance there is of
abandoning it.