]> git.donarmstrong.com Git - x_base.git/blob - .wmii/wmiirc
* fixup linking to current xsession-errors file
[x_base.git] / .wmii / wmiirc
1 #!/bin/sh -f
2 # Configure wmii
3
4 # Configuration Variables
5 MODKEY=Mod4
6 UP=k
7 DOWN=j
8 LEFT=h
9 RIGHT=l
10
11 # Colors tuples: "<text> <background> <border>"
12 WMII_NORMCOLORS='#bbbbbb #111111 #333333'
13 WMII_FOCUSCOLORS='#ffffff #285577 #4c7899'
14 #WMII_FOCUSCOLORS='#ffffff #153F1F #2A7F3F'
15
16 WMII_BACKGROUND='#111111'
17 WMII_FONT='-*-fixed-medium-r-*-*-15-*-*-*-*-*-*-*'
18
19 set -- $(echo $WMII_NORMCOLORS $WMII_FOCUSCOLORS)
20 WMII_MENU="dmenu -b -fn $WMII_FONT -nf $1 -nb $2 -sf $4 -sb $5"
21 WMII_9MENU="wmii9menu -font $WMII_FONT -nf $1 -nb $2 -sf $4 -sb $5 -br $6"
22 WMII_TERM="x-terminal-emulator"
23
24 # Column Rules
25 wmiir write /colrules <<!
26 /.*/ -> 58+42
27 !
28
29 # Tagging Rules
30 wmiir write /tagrules <<!
31 /MPlayer.*/ -> ~
32 /.*/ -> !
33 /.*/ -> 1
34 !
35
36 # Status Bar Info
37 status() {
38         echo -n $(uptime | sed 's/.*://; s/,//g') '|' $(date)
39 }
40
41 # Event processing
42 #  Processed later by `wmiiloop' and evaled.
43 #  Duplicate the eval line and replace 'eval' with 'echo' for details.
44 eventstuff() {
45         cat <<'!'
46         # Events
47         Event Start
48                 case "$1" in
49                 wmiirc)
50                         exit;
51                 esac
52         Event Key
53                 fn=$(echo "$@" | sed 's/[^a-zA-Z_0-9]/_/g')
54                 Key_$fn "$@"
55         Event CreateTag
56                 echo "$WMII_NORMCOLORS" "$@" | wmiir create "/lbar/$@"
57         Event DestroyTag
58                 wmiir remove "/lbar/$@"
59         Event FocusTag
60                 wmiir xwrite "/lbar/$@" "$WMII_FOCUSCOLORS" "$@"
61         Event UnfocusTag
62                 wmiir xwrite "/lbar/$@" "$WMII_NORMCOLORS" "$@"
63         Event UrgentTag
64                 shift
65                 wmiir xwrite "/lbar/$@" "*$@"
66         Event NotUrgentTag
67                 shift
68                 wmiir xwrite "/lbar/$@" "$@"
69         Event LeftBarClick
70                 shift
71                 wmiir xwrite /ctl view "$@"
72         # Actions
73         Action quit
74                 wmiir xwrite /ctl quit
75         Action rehash
76                 proglist $PATH >$progsfile
77         Action status
78                 set +xv
79                 if wmiir remove /rbar/status 2>/dev/null; then
80                         sleep 2
81                 fi
82                 echo "$WMII_NORMCOLORS" | wmiir create /rbar/status
83                 while status | wmiir write /rbar/status; do
84                         sleep 1
85                 done
86         Event ClientMouseDown
87                 client=$1; button=$2
88                 case "$button" in
89                 3)
90                         do=$($WMII_9MENU -initial "${menulast:-SomeRandomName}" Nop Delete)
91                         case "$do" in
92                         Delete)
93                                 wmiir xwrite /client/$client/ctl kill
94                         esac
95                         menulast=${do:-"$menulast"}
96                 esac
97         # Key Bindings
98         Key $MODKEY-Control-t
99                 case $(wmiir read /keys | wc -l | tr -d ' \t\n') in
100                 0|1)
101                         echo -n \$Keys | tr ' ' '\012' | wmiir write /keys
102                         wmiir xwrite /ctl grabmod $MODKEY;;
103                 *)
104                         wmiir xwrite /keys $MODKEY-Control-t
105                         wmiir xwrite /ctl grabmod Mod3;;
106                 esac
107         Key $MODKEY-space
108                 wmiir xwrite /tag/sel/ctl select toggle
109         Key $MODKEY-d
110                 wmiir xwrite /tag/sel/ctl colmode sel default
111         Key $MODKEY-s
112                 wmiir xwrite /tag/sel/ctl colmode sel stack
113         Key $MODKEY-m
114                 wmiir xwrite /tag/sel/ctl colmode sel max
115         Key $MODKEY-a
116                 Action $(actionlist | $WMII_MENU) &
117         Key $MODKEY-p
118                 sh -c "$($WMII_MENU <$progsfile)" &
119         Key $MODKEY-t
120                 wmiir xwrite /ctl "view $(tagsmenu)" &
121         Key $MODKEY-Return
122                 $WMII_TERM &
123         Key $MODKEY-Shift-space
124                 wmiir xwrite /tag/sel/ctl send sel toggle
125         Key $MODKEY-Shift-c
126                 wmiir xwrite /client/sel/ctl kill
127         Key $MODKEY-Shift-t
128                 wmiir xwrite "/client/$(wmiir read /client/sel/ctl)/tags" "$(tagsmenu)" &
129         Key $MODKEY-$LEFT
130                 wmiir xwrite /tag/sel/ctl select left
131         Key $MODKEY-$RIGHT
132                 wmiir xwrite /tag/sel/ctl select right
133         Key $MODKEY-$DOWN
134                 wmiir xwrite /tag/sel/ctl select down
135         Key $MODKEY-$UP
136                 wmiir xwrite /tag/sel/ctl select up
137         Key $MODKEY-Shift-$LEFT
138                 wmiir xwrite /tag/sel/ctl send sel left
139         Key $MODKEY-Shift-$RIGHT
140                 wmiir xwrite /tag/sel/ctl send sel right
141         Key $MODKEY-Shift-$DOWN
142                 wmiir xwrite /tag/sel/ctl send sel down
143         Key $MODKEY-Shift-$UP
144                 wmiir xwrite /tag/sel/ctl send sel up
145 !
146         for i in 0 1 2 3 4 5 6 7 8 9; do
147                 cat <<!
148         Key $MODKEY-$i
149                 wmiir xwrite /ctl view "$i"
150         Key $MODKEY-Shift-$i
151                 wmiir xwrite /client/sel/tags "$i"
152 !
153         done
154 }
155
156 # WM Configuration
157 wmiir write /ctl << EOF
158 font $WMII_FONT
159 focuscolors $WMII_FOCUSCOLORS
160 normcolors $WMII_NORMCOLORS
161 grabmod $MODKEY
162 border 1
163 EOF
164
165 # Feed events to `wmiiloop' for processing
166 echo "$(eventstuff | sed 's/^[  ]//' )" >> ~/.eventstuff
167 eval "$(eventstuff | sed 's/^[  ]//' | { . wmiiloop; })"
168
169 # Functions
170 Action() {
171         action=$1; shift
172         if [ -n "$action" ]; then
173                 Action_$action "$@" \
174                 || conf_which $action "$@"
175         fi
176 }
177
178 proglist() {
179         paths=$(echo "$@" | sed 'y/:/ /')
180         ls -lL $paths 2>/dev/null \
181                 | awk '$1 ~ /^[^d].*x/ { print $NF }' \
182                 | sort | uniq
183 }
184
185 # Misc
186 progsfile="$WMII_NS_DIR/.proglist"
187 Action status &
188 proglist $PATH >$progsfile &
189
190 if [ -x /usr/bin/feh ] && [ -r /home/don/media/pictures/shards_of_aleysa.jpg ]; then
191     /usr/bin/feh --bg-scale /home/don/media/pictures/shards_of_aleysa.jpg
192 fi;
193
194
195 export WMII_MENU WMII_9MENU WMII_FONT WMII_TERM
196 export WMII_FOCUSCOLORS WMII_SELCOLORS WMII_NORMCOLORS
197
198 # Setup Tag Bar
199 wmiir ls /lbar |
200 while read bar; do
201         wmiir remove "/lbar/$bar"
202 done
203 seltag="$(wmiir read /tag/sel/ctl 2>/dev/null)"
204 wmiir ls /tag | sed -e 's|/||; /^sel$/d' |
205 while read tag; do
206         if [ "X$tag" = "X$seltag" ]; then
207                 echo "$WMII_FOCUSCOLORS" "$tag" | wmiir create "/lbar/$tag" 
208         else
209                 echo "$WMII_NORMCOLORS" "$tag" | wmiir create "/lbar/$tag"
210         fi
211 done
212
213 # More functions
214 tagsmenu() {
215         wmiir ls /tag | sed 's|/||; /^sel$/d' | $WMII_MENU
216 }
217
218 actionlist() {
219         {       proglist $WMII_CONFPATH
220                 echo -n $Actions | tr ' ' '\012'
221         } | sort | uniq
222 }
223
224 conf_which() {
225         which=$(which which)
226         prog=$(PATH="$WMII_CONFPATH" $which $1)
227         shift
228         if [ -n "$prog" ]; then
229                 $prog
230         fi
231 }
232
233 # Stop any running instances of wmiirc
234 echo Start wmiirc | wmiir write /event || exit 1
235
236 wmiir read /event |
237 while read event; do
238         set -- $event
239         event=$1; shift
240         Event_$event $@
241 done 2>/dev/null