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