Advertisement
Guest User

n0dix

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