Mod1-Shift-Return and Mod1-Shift-p will launch an xterm/program on another tag and...
[wmiirc-lua.git] / wmiirc.sh
blob2c988a55dde470a9b1174e208c99b2b4dacc1ea5
1 #!/bin/sh -f
2 # Configure wmii
4 # Configuration Variables
5 MODKEY=Mod1
6 UP=k
7 DOWN=j
8 LEFT=h
9 RIGHT=l
11 # Colors tuples: "<text> <background> <border>"
12 WMII_NORMCOLORS='#222222 #5FBF77 #2A7F3F'
13 WMII_FOCUSCOLORS='#ffffff #153F1F #2A7F3F'
15 WMII_BACKGROUND='#333333'
16 WMII_FONT='-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*'
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="xterm"
23 # Column Rules
24 wmiir write /colrules <<!
25 /.*/ -> 58+42
28 # Tagging Rules
29 wmiir write /tagrules <<!
30 /XMMS.*/ -> ~
31 /MPlayer.*/ -> ~
32 /.*/ -> sel
33 /.*/ -> 1
36 # Status Bar Info
37 status() {
38 echo -n $(uptime | sed 's/.*://; s/,//g') '|' $(date)
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 exec
76 wmiir xwrite /ctl exec "$@"
77 Action rehash
78 proglist $PATH >$progsfile
79 Action status
80 set +xv
81 if wmiir remove /rbar/status 2>/dev/null; then
82 sleep 2
84 echo "$WMII_NORMCOLORS" | wmiir create /rbar/status
85 while status | wmiir write /rbar/status; do
86 sleep 1
87 done
88 Event ClientMouseDown
89 client=$1; button=$2
90 case "$button" in
92 do=$($WMII_9MENU -initial "${menulast:-SomeRandomName}" Nop Delete)
93 case "$do" in
94 Delete)
95 wmiir xwrite /client/$client/ctl kill
96 esac
97 menulast=${do:-"$menulast"}
98 esac
99 # Key Bindings
100 Key $MODKEY-Control-t
101 case $(wmiir read /keys | wc -l | tr -d ' \t\n') in
102 0|1)
103 echo -n \$Keys | tr ' ' '\012' | wmiir write /keys
104 wmiir xwrite /ctl grabmod $MODKEY;;
106 wmiir xwrite /keys $MODKEY-Control-t
107 wmiir xwrite /ctl grabmod Mod3;;
108 esac
109 Key $MODKEY-space
110 wmiir xwrite /tag/sel/ctl select toggle
111 Key $MODKEY-d
112 wmiir xwrite /tag/sel/ctl colmode sel default
113 Key $MODKEY-s
114 wmiir xwrite /tag/sel/ctl colmode sel stack
115 Key $MODKEY-m
116 wmiir xwrite /tag/sel/ctl colmode sel max
117 Key $MODKEY-a
118 Action $(actionlist | $WMII_MENU) &
119 Key $MODKEY-p
120 sh -c "$($WMII_MENU <$progsfile)" &
121 Key $MODKEY-t
122 wmiir xwrite /ctl "view $(tagsmenu)" &
123 Key $MODKEY-Return
124 $WMII_TERM &
125 Key $MODKEY-Shift-space
126 wmiir xwrite /tag/sel/ctl send sel toggle
127 Key $MODKEY-Shift-c
128 wmiir xwrite /client/sel/ctl kill
129 Key $MODKEY-Shift-t
130 wmiir xwrite "/client/$(wmiir read /client/sel/ctl)/tags" "$(tagsmenu)" &
131 Key $MODKEY-$LEFT
132 wmiir xwrite /tag/sel/ctl select left
133 Key $MODKEY-$RIGHT
134 wmiir xwrite /tag/sel/ctl select right
135 Key $MODKEY-$DOWN
136 wmiir xwrite /tag/sel/ctl select down
137 Key $MODKEY-$UP
138 wmiir xwrite /tag/sel/ctl select up
139 Key $MODKEY-Shift-$LEFT
140 wmiir xwrite /tag/sel/ctl send sel left
141 Key $MODKEY-Shift-$RIGHT
142 wmiir xwrite /tag/sel/ctl send sel right
143 Key $MODKEY-Shift-$DOWN
144 wmiir xwrite /tag/sel/ctl send sel down
145 Key $MODKEY-Shift-$UP
146 wmiir xwrite /tag/sel/ctl send sel up
148 for i in 0 1 2 3 4 5 6 7 8 9; do
149 cat <<!
150 Key $MODKEY-$i
151 wmiir xwrite /ctl view "$i"
152 Key $MODKEY-Shift-$i
153 wmiir xwrite /client/sel/tags "$i"
155 done
158 # WM Configuration
159 wmiir write /ctl << EOF
160 font $WMII_FONT
161 focuscolors $WMII_FOCUSCOLORS
162 normcolors $WMII_NORMCOLORS
163 grabmod $MODKEY
164 border 1
167 export WMII_MENU WMII_9MENU WMII_FONT WMII_TERM
168 export WMII_FOCUSCOLORS WMII_SELCOLORS WMII_NORMCOLORS
170 # Feed events to `wmiiloop' for processing
171 eval "$(eventstuff | sed 's/^[ ]//' | { . wmiiloop; })"
173 echo "$Keys" | tr ' ' '\n' | wmiir write /keys
175 # Functions
176 Action() {
177 action=$1; shift
178 if [ -n "$action" ]; then
179 Action_$action "$@" \
180 || conf_which $action "$@"
184 proglist() {
185 paths=$(echo "$@" | sed 'y/:/ /')
186 ls -lL $paths 2>/dev/null \
187 | awk '$1 ~ /^[^d].*x/ { print $NF }' \
188 | sort | uniq
191 # Misc
192 progsfile="$WMII_NS_DIR/.proglist"
193 Action status &
194 proglist $PATH >$progsfile &
196 xsetroot -solid "$WMII_BACKGROUND" &
198 # Setup Tag Bar
199 seltag="$(wmiir read /tag/sel/ctl 2>/dev/null)"
200 wmiir ls /lbar |
201 while read bar; do
202 wmiir remove "/lbar/$bar"
203 done
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"
211 done
213 # More functions
214 tagsmenu() {
215 wmiir ls /tag | sed 's|/||; /^sel$/d' | $WMII_MENU
218 actionlist() {
219 { proglist $WMII_CONFPATH
220 echo -n $Actions | tr ' ' '\012'
221 } | sort | uniq
224 conf_which() {
225 which=$(which which)
226 prog=$(PATH="$WMII_CONFPATH" $which $1); shift
227 [ -n "$prog" ] && $prog "$@"
230 # Stop any running instances of wmiirc
231 echo Start wmiirc | wmiir write /event || exit 1
233 wmiir read /event |
234 while read event; do
235 set -- $event
236 event=$1; shift
237 Event_$event $@
238 done 2>/dev/null