wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

sh.wmii (6094B)


      1 #!sh
      2 # WMII Configuration
      3 load std string regex expr echo
      4 
      5 argv0 = $0
      6 
      7 #mount -Aa {os dial unix!/tmp/ns.kris.:1/wmii >[1=0]} / || raise mount
      8 #mount -Aa {styxmon {os rc -c 'dial $WMII_ADDRESS' >[1=0]}} / || raise mount
      9 mount -Aa {os rc -c 'dial $WMII_ADDRESS' >[1=0]} / || raise mount
     10 
     11 {`{read} && echo halt>/dev/sysctl}&
     12 
     13 MODKEY=Mod1
     14 UP=k
     15 DOWN=j
     16 LEFT=h
     17 RIGHT=l
     18 
     19 WMII_FONT=fixed
     20 WMII_NORMCOLORS=('#222222' '#5FBF77' '#2A7F3F')
     21 WMII_FOCUSCOLORS=('#ffffff' '#153F1F' '#2A7F3F')
     22 WMII_BACKGROUND='#333333'
     23 
     24 WMII_TERM=urxvt
     25 
     26 fn wmiimenu {
     27 	(nf nb nil sf sb nil) := ($WMII_NORMCOLORS $WMII_FOCUSCOLORS)
     28 	os -d ${hostenv HOME} (
     29 		dmenu -b -fn $WMII_FONT
     30 		-nf $nf -nb $nb -sf $sf -sb $sb)
     31 }
     32 
     33 fn 9menu {
     34 	os -d ${hostenv HOME} (
     35 		wmii9menu -font ${hd ${split , $WMII_FONT}}
     36 		-^(nf nb br)^$WMII_NORMCOLORS
     37 		-^(sf sb br)^$WMII_FOCUSCOLORS $*)
     38 }
     39 
     40 # Column Rules
     41 echo '/./ -> 60+40' >/colrules
     42 
     43 # Tagging Rules
     44 echo '
     45 /Firefox/ -> www
     46 /XMMS.*/ -> ~
     47 /MPlayer.*/ -> ~
     48 /.*/ -> sel
     49 ' >/tagrules
     50 
     51 subfn seq {
     52 	result=${expr $* seq}
     53 }
     54 
     55 subfn hostenv {
     56 	arg := $"*
     57 	result="{os rc -c 'echo -n $'^$arg </dev/null}
     58 }
     59 
     60 subfn ftl {
     61 	result=${tl $*}
     62 	result=$"result
     63 }
     64 
     65 subfn lines {
     66 	ifs := "{echo}
     67 	arg := $*
     68 	result = `{$arg}
     69 }
     70 
     71 fn 'fn?' {
     72 	args := $*
     73 	~ ("{rescue '*' {} {whatis $args >[2]/dev/null}}
     74 	   'load std; fn '*)
     75 }
     76 
     77 fn ifx {
     78 	(pred fn val args) := $*
     79 	if {$pred $val} {$fn $val $args}
     80 }
     81 
     82 fn dofn {
     83 	ifx 'fn?' {$*} $*
     84 }
     85 
     86 fn run_command {
     87 	os -b -d ${hostenv HOME} $* &
     88 }
     89 
     90 fn dprint {
     91 	arg := $*
     92 	or {~ $#debug 0} {~ $debug '' 0} { echo $arg }
     93 }
     94 
     95 subfn config_whatis {
     96 	result=${lines {os rc -c 'PATH=$WMII_CONFPATH which $*' $* </dev/null} $*}
     97 }
     98 
     99 # Status Bar Info
    100 fn status {
    101 	echo ${re mg '[0-9]+\.[0-9]+' "{os uptime}} '|' `{date}
    102 }
    103 
    104 for(i in Key Event Action) {
    105 	'{fn $i { fn '$i'-$1 ${tl $*} }}'
    106 }
    107 
    108 # Events
    109 Event Start {
    110 	if {~ $1 wmiirc} {
    111 		rm -f $progs_file
    112 		exit
    113 	}
    114 }
    115 
    116 Event Key {
    117 	dprint Key-$1
    118 	Key-$1 $1
    119 }
    120 
    121 Event CreateTag { echo $WMII_NORMCOLORS $* > /lbar/$"* }
    122 Event DestroyTag { rm /lbar/$"* }
    123 Event FocusTag { echo $WMII_FOCUSCOLORS $* > /lbar/$"* }
    124 Event UnfocusTag { echo $WMII_NORMCOLORS $* > /lbar/$"* }
    125 Event UrgentTag { echo '*'${ftl $*} > /lbar/${ftl $*} }
    126 Event NotUrgentTag { echo ${tl $*} > /lbar/${ftl $*} }
    127 
    128 Event LeftBarClick {
    129 	(button name) := $*
    130 	if {~ $button 1} { echo view $name >/ctl }
    131 }
    132 Event LeftBarMouseDown {
    133 	(button name) := $*
    134 	if {~ $button 3} { echo view "{9menu ${lines read_tags}} >/ctl & }
    135 }
    136 lastcmd=''
    137 Event ClientMouseDown {
    138 	(client button) := $*
    139 	if {~ $button 3} {
    140 		lastcmd = `{9menu -initial $lastcmd Nop Delete Fullscreen}
    141 		if{~ $#lastcmd 0} {lastcmd=''}
    142 		cmp := {~ $lastcmd $*}
    143 		if {$cmp Nop} {
    144 		} {$cmp Delete} { echo kill >/client/$client/ctl
    145 		} {$cmp Fullscreen} { echo Fullscreen toggle >/client/$client/ctl
    146 		}
    147 	}
    148 }
    149 
    150 # Actions
    151 Action quit { echo quit >>/ctl }
    152 Action rehash {
    153 	flag x -
    154 	proglist ${hostenv PATH} >$progs_file
    155 }
    156 Action status {
    157 	flag x -
    158 	if {rm /rbar/status >[2]/dev/null} { sleep 1 }
    159 	echo $WMII_NORMCOLORS >/rbar/status
    160 	while {status >/rbar/status} { sleep 1 }
    161 }
    162 
    163 ifx {ftest -x $*} {run $*} $home/.wmii-3.5/sh.wmii.local
    164 fn Key { ifx {! 'fn?' $*} {fn $*} Key-$1 ${tl $*} }
    165 
    166 fn Action {
    167 	(action args) := $*
    168 	or {dofn Action-$action $args} {
    169 		ifx {! ~ $#* 0} {run_command $*} ${config_whatis $action} $args
    170 	}
    171 }
    172 
    173 # Key Bindings
    174 Key $MODKEY-Control-t {
    175 	if { ~ `{wc -l /keys} 0 1} {
    176 		initkeys
    177 		echo grabmod $MODKEY >/ctl
    178 	} {
    179 		echo $MODKEY-Control-t >/keys
    180 		echo grabmod Mod3 >/ctl
    181 	}
    182 }
    183 
    184 Key $MODKEY-$LEFT { echo select left >/tag/sel/ctl }
    185 Key $MODKEY-$RIGHT { echo select right >/tag/sel/ctl }
    186 Key $MODKEY-$UP { echo select up >/tag/sel/ctl }
    187 Key $MODKEY-$DOWN { echo select down >/tag/sel/ctl }
    188 
    189 Key $MODKEY-Shift-$LEFT { echo send sel left >/tag/sel/ctl }
    190 Key $MODKEY-Shift-$RIGHT { echo send sel right >/tag/sel/ctl }
    191 Key $MODKEY-Shift-$DOWN { echo send sel down >/tag/sel/ctl }
    192 Key $MODKEY-Shift-$UP { echo send sel up >/tag/sel/ctl }
    193 
    194 Key $MODKEY-space { echo select toggle >/tag/sel/ctl }
    195 Key $MODKEY-Shift-space { echo send sel toggle >/tag/sel/ctl }
    196 
    197 Key $MODKEY-d { echo colmode sel default >/tag/sel/ctl }
    198 Key $MODKEY-s { echo colmode sel stack >/tag/sel/ctl }
    199 Key $MODKEY-m { echo colmode sel max >/tag/sel/ctl }
    200 
    201 Key $MODKEY-f { echo Fullscreen toggle >/client/sel/ctl }
    202 
    203 Key $MODKEY-Shift-c { echo kill >/client/sel/ctl }
    204 
    205 Key $MODKEY-a { Action `{actionlist | wmiimenu} & }
    206 Key $MODKEY-p { run_command rc -c "{wmiimenu <$progs_file} & }
    207 Key $MODKEY-Return { run_command $WMII_TERM & }
    208 Key $MODKEY-t { echo view `{read_tags | wmiimenu} >/ctl & }
    209 Key $MODKEY-Shift-t {
    210 	sel := "{cat /client/sel/ctl}
    211 	read_tags | wmiimenu >/client/$sel/tags
    212 }
    213 
    214 Key $MODKEY-^${seq 0 9} { echo view ${tl ${splitr $1 -}} >/ctl }
    215 Key Shift-$MODKEY-${seq 0 9} { echo ${tl ${splitr $1 -}} >/client/sel/tags}
    216 
    217 # Functions
    218 fn proglist {
    219 	os find ${split : $"*} -maxdepth 1 -type f </dev/null | sed 's,.*/,,' | sort | uniq
    220 	#for(d in /n/local^${split : $"*}) {
    221 	#	fs filter {mode -d} $d
    222 	#} | sed 's,.*/,,' | sort | uniq
    223 }
    224 
    225 fn getfuns {
    226 	ls -p /env | sed -n 's/^fn-' ^ $1 ^ '-//p'
    227 }
    228 
    229 fn actionlist {
    230 	{	rescue '*' {} {
    231 			proglist ${hostenv WMII_CONFPATH}
    232 		}
    233 	 	getfuns Action
    234 	} | sort | uniq
    235 }
    236 
    237 fn initkeys {
    238 	getfuns Key >/keys
    239 }
    240 
    241 fn read_tags {
    242 	ls -p /tag | grep -v '^sel$'
    243 }
    244 
    245 # WM Configuration
    246 {
    247 	echo grabmod $MODKEY
    248 	echo border 2
    249 	echo font $WMII_FONT
    250 	echo focuscolors $WMII_FOCUSCOLORS
    251 	echo normcolors $WMII_NORMCOLORS
    252 } >/ctl
    253 
    254 # Misc Setup
    255 os xsetroot -solid $WMII_BACKGROUND </dev/null
    256 
    257 dofn Local-Overrides
    258 
    259 Action status &
    260 progs_file=/tmp/proglist.${pid}
    261 Action rehash &
    262 
    263 # Tag Bar Setup
    264 seltag=${lines sed 1q /tag/sel/ctl}
    265 comm -13 ${pipe from {read_tags}} ${pipe from {ls -p /lbar/*}} |
    266 	getlines { rm /lbar/$line }
    267 read_tags | getlines {
    268 	if {~ $line $seltag} {
    269 		echo $WMII_FOCUSCOLORS $line
    270 	} {
    271 		echo $WMII_NORMCOLORS $line
    272 	} >/lbar/$line
    273 }
    274 
    275 # Keygrab Setup
    276 initkeys
    277 
    278 echo Start wmiirc >/event
    279 
    280 # Event Loop
    281 getlines {
    282 	(event args) := ${split ' 	' $line}
    283 	dprint Event-$event: $args
    284 	rescue '*' { dprint Exception: $exception } {
    285 		dofn Event-$event $args
    286 	} </dev/null
    287 	dprint loop
    288 } </event
    289