]> git.donarmstrong.com Git - x_base.git/blob - .wmii/rc.wmii
* fixup linking to current xsession-errors file
[x_base.git] / .wmii / rc.wmii
1 #!/usr/bin/env wmii9rc
2 # WMII Configuration
3
4 oldpath=$path
5 path=($PLAN9/bin $path)
6
7 MODKEY=Mod4
8 UP=k
9 DOWN=j
10 LEFT=h
11 RIGHT=l
12
13 WMII_FONT='fixed'
14 WMII_NORMCOLORS=('#222222' '#5FBF77' '#2A7F3F')
15 WMII_FOCUSCOLORS=('#ffffff' '#153F1F' '#2A7F3F')
16 WMII_BACKGROUND='#333333'
17
18 WMII_TERM=(xterm)
19
20 fn wmiimenu {
21         dmenu -b -fn $WMII_FONT \
22                 -nf $WMII_NORMCOLORS(1) -nb $WMII_NORMCOLORS(2) \
23                 -sf $WMII_FOCUSCOLORS(1) -sb $WMII_FOCUSCOLORS(2)
24 }
25
26 fn 9menu {
27         wmii9menu -font $WMII_FONT \
28                 -^(nf nb br)^$WMII_NORMCOLORS \
29                 -^(sf sb br)^$WMII_FOCUSCOLORS $*
30 }
31
32 fn config_whatis {
33         confpath=`{echo $WMII_CONFPATH | sed 'y/:/ /'}
34         prog=$1; shift
35         echo `{{path=$confpath whatis $prog} | grep -v '=|^fn '} $*
36 }
37
38 if(echo $0 | grep -vs '/rc.wmii$') {
39         echo Fatal: This file should only be run as rc.wmii >[1=2]
40         exit badname
41 }
42
43 if(! test -x $PLAN9/bin/read) {
44         echo 'Can''t find the ''read'' command' >[1=2]
45         xmessage -file - <<'!'
46         exec `{config_whatis wmiirc}
47 }
48 rc.wmii can't run:
49         You have a Plan 9 utilities installed, but are missing the 'read' command.
50         This likely means that you have an out-of-date 9base installed.
51
52 wmiirc will be run instead.
53 !
54
55 # Source Variables, &c
56 local = `{config_whatis rc.wmii.local}
57 . <{awk '//; /^# Overrides/ { exit }' $local </dev/null}
58
59 # Column Rules
60 wmiir write /colrules <<!
61 /./ -> 60+40
62 !
63
64 # Tagging Rules
65 wmiir write /tagrules <<!
66 /XMMS.*/ -> ~
67 /MPlayer.*/ -> ~
68 /.*/ -> !
69 /.*/ -> 1
70 !
71
72 # Status Bar Info
73 fn status {
74         echo -n `{uptime | sed 's/.*://; s/,//g'} '|' `{date}
75 }
76
77 # View Titles
78 fn viewtitle { echo $* }
79
80 # Events
81 fn Event-Start {
82         switch($1) {
83         case wmiirc
84                 rm -f $progs_file
85                 exit
86         }
87 }
88
89 fn Event-Key { eval Key-$1 $1 }
90
91 fn Event-CreateTag { echo $WMII_NORMCOLORS `{viewtitle $*} | wmiir create /lbar/$"* }
92 fn Event-DestroyTag { wmiir remove /lbar/$"* }
93 fn Event-FocusTag { wmiir xwrite /lbar/$"* $WMII_FOCUSCOLORS `{viewtitle $*} }
94 fn Event-UnfocusTag { wmiir xwrite /lbar/$"* $WMII_NORMCOLORS `{viewtitle $*} }
95 fn Event-UrgentTag { shift; wmiir xwrite /lbar/$"* '*'$"* }
96 fn Event-NotUrgentTag { shift; wmiir xwrite /lbar/$"* $"* }
97
98 fn Event-LeftBarClick { shift; wmiir xwrite /ctl view $* }
99
100 menulast = ''
101 fn Event-ClientMouseDown {
102         client = $1; button = $2
103         if(~ $button 3) {
104                 do=`{9menu -initial $menulast Nop Delete}
105                 switch($do) {
106                 case Delete
107                         wmiir xwrite /client/$client/ctl kill
108                 }
109                 if(! ~ $#do 0)
110                         menulast = $do;
111         }
112 }
113
114 # Actions
115 fn Action {
116         action=$1; shift
117         if(whatis Action-$action | grep -s '^fn ') {
118                 Action-$action $* &
119         };if not {
120                 run_command `{config_whatis $action} $* &
121         }
122 }
123 fn Action-rehash { proglist $PATH >$progs_file }
124 fn Action-quit { wmiir xwrite /ctl quit }
125 fn Action-status {
126         flag x -
127         flag r -
128         if(wmiir remove /rbar/status >[2]/dev/null)
129                 sleep 2
130         echo $WMII_NORMCOLORS | wmiir create /rbar/status
131         while(status | wmiir write /rbar/status)
132                 sleep 1
133 }
134
135 # Key Bindings
136 fn Key-$MODKEY-Control-t {
137         switch(`{wmiir read /keys | wc -l}) {
138         case 0 1
139                 initkeys
140                 wmiir xwrite /ctl grabmod $MODKEY
141         case *
142                 wmiir xwrite /keys $MODKEY-Control-t
143                 wmiir xwrite /ctl grabmod Mod3
144         }
145 }
146
147 fn Key-$MODKEY-$LEFT { wmiir xwrite /tag/sel/ctl select left }
148 fn Key-$MODKEY-$RIGHT { wmiir xwrite /tag/sel/ctl select right }
149 fn Key-$MODKEY-$DOWN { wmiir xwrite /tag/sel/ctl select down }
150 fn Key-$MODKEY-$UP { wmiir xwrite /tag/sel/ctl select up }
151
152 fn Key-$MODKEY-Shift-$LEFT { wmiir xwrite /tag/sel/ctl send sel left }
153 fn Key-$MODKEY-Shift-$RIGHT { wmiir xwrite /tag/sel/ctl send sel right }
154 fn Key-$MODKEY-Shift-$DOWN { wmiir xwrite /tag/sel/ctl send sel down }
155 fn Key-$MODKEY-Shift-$UP { wmiir xwrite /tag/sel/ctl send sel up }
156
157 fn Key-$MODKEY-space { wmiir xwrite /tag/sel/ctl select toggle }
158 fn Key-$MODKEY-Shift-space { wmiir xwrite /tag/sel/ctl send sel toggle }
159
160 fn Key-$MODKEY-d { wmiir xwrite /tag/sel/ctl colmode sel default }
161 fn Key-$MODKEY-s { wmiir xwrite /tag/sel/ctl colmode sel stack }
162 fn Key-$MODKEY-m { wmiir xwrite /tag/sel/ctl colmode sel max }
163
164 fn Key-$MODKEY-Shift-c { wmiir xwrite /client/sel/ctl kill }
165
166 fn Key-$MODKEY-a { Action `{actionlist | wmiimenu} & }
167 fn Key-$MODKEY-p { run_command `{wmiimenu <$progs_file} & }
168 fn Key-$MODKEY-Return { run_command $WMII_TERM & }
169 fn Key-$MODKEY-t { wmiir xwrite /ctl view `{read_tags | wmiimenu} & }
170 fn Key-$MODKEY-Shift-t {
171         wmiir xwrite /client/`{wmiir read /client/sel/ctl}^/tags `{read_tags | wmiimenu} &
172 }
173
174 for(i in `{seq 0 9}) {
175         fn Key-$MODKEY-$i { wmiir xwrite /ctl view `{echo $1 | sed 's/.*-//'} }
176         fn Key-Shift-$MODKEY-$i {wmiir xwrite /client/sel/tags `{echo $1 | sed 's/.*-//'} }
177 }
178
179 # Functions
180 fn proglist {
181         /bin/ls -lL `{echo $* | sed 'y/:/ /'} >[2]/dev/null \
182                 | awk '$1 ~ /^[^d].*x/ { print $NF }' \
183                 | sort | uniq
184 }
185
186 fn getfuns {
187         env | sed -n 's/^fn#'^$1^'-([^=]+).*/\1/p'
188 }
189
190 fn actionlist {
191         {       proglist $WMII_CONFPATH
192                 getfuns Action
193         } | sort | uniq
194 }
195
196 fn initkeys {
197         getfuns Key | wmiir write /keys
198 }
199
200 fn read_tags {
201         wmiir ls /tag | sed 's,/,,; /^sel$/d'
202 }
203
204 fn run_command {
205         @{      rfork ns
206                 path=$oldpath
207                 eval exec $*
208         }
209 }
210
211 # WM Configuration
212 wmiir write /ctl <<!
213 grabmod $MODKEY
214 border 2
215 font $WMII_FONT
216 focuscolors $WMII_FOCUSCOLORS
217 normcolors $WMII_NORMCOLORS
218 !
219 xsetroot -solid $WMII_BACKGROUND
220
221 # Source Overrides
222 . <{awk '/^# Overrides/, 0' $local </dev/null}
223
224 # Misc Setup
225 Action status &
226 progs_file=$WMII_NS_DIR/proglist.$pid
227 proglist $PATH >$progs_file &
228
229 # Tag Bar Setup
230 ifs='#
231 '{      for(bar in `{comm -23 <{wmiir ls /lbar} <{read_tags}})
232                 wmiir remove /lbar/$bar
233         seltag=`{wmiir read /tag/sel/ctl}
234         for(tag in `{read_tags}) {
235                 if(~ $tag $seltag)
236                         echo $WMII_FOCUSCOLORS `{viewtitle $tag} | wmiir create /lbar/$tag
237                 if not
238                         echo $WMII_NORMCOLORS `{viewtitle $tag} | wmiir create /lbar/$tag
239         }
240 }
241
242 # Keygrab Setup
243 initkeys
244
245 if(echo Start wmiirc | ! wmiir write /event >[2]/dev/null)
246         exit 1
247
248 # Event Loop
249 wmiir read /event |
250         while(*=`{read}) {
251                 event = $1; shift
252                 Event-$event $*
253         } >[2]/dev/null </dev/null
254