wmiiscript=$1 wmiikeys=() echo Start $wmiiscript | wmiir write /event >[2]/dev/null \ || exit write if(~ $scriptname '') scriptname=$wmiiscript # Blech. if(! test -x $PLAN9/bin/read) fn read { sh -c 'read -r x || exit 1; echo $x' } fn wi_atexit {} fn sigexit { wi_atexit } fn Event-Start { if(~ $1 $wmiiscript) exit } fn Event-Key { Key-$1 $1 } fn wi_fatal { echo $scriptname: Fatal: $* exit fatal } fn wi_notice { xmessage $scriptname: Notice: $* } fn wi_readctl { wmiir read /ctl | sed -n 's/^'$1' (.*)/\1/p' } wmiifont=`{wi_readctl font} wmiinormcol=`{wi_readctl normcolors} wmiifocuscol=`{wi_readctl focuscolors} fn wi_menu { dmenu -b -fn $wmiifont \ -nf $wmiinormcol(1) -nb $wmiinormcol(2) \ -sf $wmiifocuscol(1) -sb $wmiifocuscol(2) } fn wi_9menu { wmii9menu -font `{echo $wmiifont | sed 's/,.*//'} \ -^(nf nb br)^$wmiinormcol \ -^(sf sb br)^$wmiifocuscol $* } fn wi_proglist { /bin/ls -lL `{echo $* | sed 'y/:/ /'} >[2]/dev/null \ | awk '$1 ~ /^[^d].*x/ { print $NF }' \ | sort | uniq } fn wi_actions { { wi_proglist $WMII_CONFPATH wi_getfuns Action } | sort | uniq } fn wi_script { prog = `{@{path=$confpath whatis $1} | grep -v '^fn|= ' || echo /dev/null} shift; echo $prog $* } fn wi_initkeys { ifs=() { wmiikeys = `{wmiir read /keys} { mykeys = `{comm -23 \ <{wi_getfuns Key | sort | uniq} \ <{echo $wmiikeys | sort | uniq}} {echo $wmiikeys; wi_getfuns Key} \ | sort | uniq \ | wmiir write /keys } } fn wi_atexit { wi_cleankeys } } fn wi_cleankeys { ifs=() { wmiikeys = `{wmiir read /keys} { comm -23 <{echo $wmiikeys | sort | uniq} \ <{echo $mykeys} \ | wmiir write /keys } } } fn wi_runcmd { @{ rfork ns path=$oldpath if(~ $1 -t) { shift * = (wihack -tags `{wmiir read /tag/sel/ctl | sed 1q} $*) } eval exec $* & } } fn wi_getfuns { env | sed -n 's/^fn#'^$1^'-([^=]+).*/\1/p' } fn wi_tags { wmiir ls /tag | sed 's,/,,; /^sel$/d' } fn wi_eventloop { wi_initkeys wmiir read /event | while(*=`{read}) { event = $1; shift Event-$event $* } >[2]/dev/null