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