Advertisement
Emulatorman

wmiirc

Jan 4th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.22 KB | None | 0 0
  1. #!/bin/sh -f
  2. #
  3. # Modified wmiirc from User Guide
  4. # for wmii 3.9.2
  5. #
  6. # By Ben Smith
  7. # bensmith87@gmail.com
  8. #
  9. #
  10. # Please contact if you have any improvements
  11. #
  12. # How to setup
  13. # * Setup the wallpaper to point to a picture
  14. # * Setup the actiondir to point to a directory that contains executable scripts for things you want to do
  15. # * Change the terminal() function to call your faviourite emulator
  16. # * Add any programs to the tagrules that you use
  17. # * Install mpd and mpc, or remove mpd function, loop and key events from this script
  18. # * Setup servermail login using .netrc file in home directory, or remove mail code from this script
  19. # * Install aumix
  20. #
  21. # How to use
  22. # * Mod-Enter - new terminal
  23. # * Mod-p - programs list
  24. # * Mod-a - actions menu
  25. # * Mod-t - change to different tag
  26. # * Mod-Shift-t - move client to different tag
  27. # * Mod-[0-9] - move to the nth tag
  28. # * Click on client head
  29. # * Right click
  30. # * Delete - delete client
  31. # * Remove - remove client from view
  32. # * Kill - kill client
  33. # * Scroll - select client above or below in column
  34. # * Click tag - swap to this view
  35. # * Click mail widget
  36. # * Left mouse - Open browser with servermail
  37. # * Click mpd widget
  38. # * Left mouse - toggle play pause
  39. # * Right click - open ncmpcpp
  40. # * Scroll - change song
  41. # * Click vol widget
  42. # * Left click - toggle mute
  43. # * Scroll - change volume
  44. # * Click clock
  45. # * Left click - show calendar
  46.  
  47. up=k
  48. down=j
  49. left=h
  50. right=l
  51. modkey=Mod4
  52.  
  53. focuscolors='#000000 #cd6d37 #000000'
  54. normcolors='#000000 #848484 #000000'
  55.  
  56. font="-misc-fixed-medium-r-*-*-13-*-*-*-*-60-*-*"
  57.  
  58. wallpaper="/home/ben/pictures/wallpaper.png"
  59. feh --bg-tile $wallpaper &
  60.  
  61. actiondir="/home/ben/.wmii"
  62.  
  63. startview=comm
  64.  
  65. proglist() {
  66. IFS=: set -- $1
  67. find -L $@ -maxdepth 1 -perm /111 | sed '1d; s,.*/,,' | sort | uniq
  68. unset IFS
  69. }
  70.  
  71. terminal() {
  72. wmiir setsid urxvt "$@"
  73. }
  74.  
  75. clickmenu() {
  76. if res=$(wmii9menu -- "$@"); then
  77. eval "$res";
  78. fi
  79. }
  80.  
  81. # Configure wmii
  82. wmiir write /ctl <<!
  83. focuscolors $focuscolors
  84. normcolors $normcolors
  85. grabmod $modkey
  86. border 1
  87. font $font
  88. view $startview
  89. bar on top
  90. !
  91.  
  92. # Create initial view
  93. echo $focuscolors $startview | wmiir create /lbar/$startview
  94.  
  95.  
  96. # Column rules
  97. wmiir write /colrules <<!
  98. !
  99.  
  100. # Tag rules
  101. wmiir write /tagrules <<!
  102. /Navigator:Icecat:*/ -> sel+web
  103. /gimp:Gimp:*/ -> image+~
  104. /MATLAB:*:*/ -> matlab
  105. /sun-awt-X11-XFramePeer:com-mathworks-util-PostVMInit:*/ -> sel+matlab+~
  106. /sun-awt-X11-XDialogPeer:com-mathworks-util-PostVMInit:*/ -> sel+matlab+~
  107. /Qt-subapplication:VirtualBox:*/ -> vbox
  108. /VBoxSDL:VBoxSDL:*/ -> vbox
  109. /xchat:Xchat:*/ -> chat
  110. /Pidgin:Pidgin:*/ -> chat
  111. /*:MPlayer:*/ -> video+~
  112. /urxvt:URxvt:*/ -> sel+term
  113. /gvim:Gvim:*/ -> sel+vim
  114. !
  115.  
  116. # Create the notice bar
  117. echo $normcolors | wmiir create /rbar/!notice
  118.  
  119. # Right bar widgets
  120.  
  121. # Clock
  122. echo '#000000 #ffffff #000000' clock | wmiir create /rbar/zclock # Create the widget
  123. clock() {
  124. echo $(date '+%a %d, %b; %X')
  125. }
  126. while clock | wmiir write /rbar/zclock; do
  127. sleep 1
  128. done &
  129.  
  130. # MPD
  131. echo $normcolors mpd | wmiir create /rbar/mpd
  132. mpd() {
  133. if [ `mpc status | grep playing | wc -l` -eq 1 ]; then
  134. echo '>' `mpc status | head -n 1`
  135. else
  136. if [ `mpc status | grep paused | wc -l` -eq 1 ]; then
  137. echo '||' `mpc status | head -n 1`
  138. else
  139. echo mpd
  140. fi
  141. fi
  142. }
  143. while mpd | wmiir write /rbar/mpd; do
  144. sleep 4
  145. done &
  146.  
  147. # Volume
  148. echo $normcolors vol | wmiir create /rbar/vol
  149. vol() {
  150. echo vol $(aumix -q | grep vol | sed 's/vol [0-9]*, //' | sed 's/, P//') %
  151. }
  152. vol | wmiir write /rbar/vol
  153.  
  154. # Mail
  155. echo $normcolors mail | wmiir create /rbar/mail
  156. mail() {
  157. unread=`curl -n --silent "https://mail.mailserver.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p" | wc -l`
  158.  
  159. if [ $unread -eq 0 ]; then
  160. echo -n $normcolors mail $unread
  161. else
  162. echo -n $focuscolors mail $unread
  163. fi
  164.  
  165. }
  166. while mail | wmiir write /rbar/mail; do
  167. sleep 60
  168. done &
  169.  
  170. # Bind keys
  171. {
  172. cat <<!
  173. $modkey-$left
  174. $modkey-$right
  175. $modkey-$up
  176. $modkey-$down
  177. $modkey-space
  178. $modkey-Shift-$left
  179. $modkey-Shift-$right
  180. $modkey-Shift-$up
  181. $modkey-Shift-$down
  182. $modkey-Shift-space
  183. $modkey-d
  184. $modkey-s
  185. $modkey-m
  186. $modkey-Shift-c
  187. $modkey-f
  188. $modkey-Return
  189. $modkey-p
  190. $modkey-a
  191. $modkey-t
  192. $modkey-Shift-t
  193. !
  194. for i in 1 2 3 4 5 6 7 8 9 0; do
  195. echo $modkey-$i
  196. echo $modkey-Shift-$i
  197. done
  198. } | wmiir write /keys
  199.  
  200. # Broadcast a custom event
  201. wmiir xwrite /event Start wmiirc
  202.  
  203. # Open /event for reading
  204. wmiir read /event |
  205. # Read the events line by line
  206. while read line; do
  207. set -- $line
  208. event=$1; shift
  209. line="$(echo $line | sed 's/^[^ ]* //' | tr -d '\n')"
  210.  
  211. # echo ---------------------------------
  212. # echo event: $event
  213. # echo param1: $1
  214. # echo param2: $2
  215. # echo ---------------------------------
  216.  
  217. # Process the event
  218. case $event in
  219.  
  220. Start) # Quit when a new instance starts
  221. [ $1 = wmiirc ] && exit;;
  222.  
  223. CreateTag) # CreateTag <Tag Name>
  224. echo $normcolors $1 | wmiir create /lbar/$1;;
  225. DestroyTag) # DestroyTag <Tag Name>
  226. wmiir rm /lbar/$1;;
  227. FocusTag) # FocusTag <Tag Name>
  228. wmiir xwrite /lbar/$1 $focuscolors $1;;
  229. UnfocusTag) # UnfocusTag <Tag Name>
  230. wmiir xwrite /lbar/$1 $normcolors $1;;
  231.  
  232. Notice)
  233. echo $focuscolors $line | wmiir write /rbar/!notice
  234. #kill $xpid 2>/dev/null
  235. {
  236. sleep 5;
  237. echo $normcolors ' ' | wmiir write /rbar/!notice;
  238. } &;;
  239. #xpid = $!;;
  240.  
  241. UrgentTag) # UrgentTag <'Client' or 'Manager'> <Tag Name>
  242. wmiir xwrite /lbar/$2 "*$2";;
  243. NotUrgentTag) # NotUrgentTag <'Client' or 'Manager'> <TagName>
  244. wmiir xwrite /lbar/$2 $2;;
  245.  
  246. # Key Events
  247. Key) # Key <Key Name>
  248. case $1 in
  249. # Motion keys
  250. $modkey-$left)
  251. wmiir xwrite /tag/sel/ctl select left;;
  252. $modkey-$right)
  253. wmiir xwrite /tag/sel/ctl select right;;
  254. $modkey-$up)
  255. wmiir xwrite /tag/sel/ctl select up;;
  256. $modkey-$down)
  257. wmiir xwrite /tag/sel/ctl select down;;
  258. $modkey-space)
  259. wmiir xwrite /tag/sel/ctl select toggle;;
  260.  
  261. # Client movement
  262. $modkey-Shift-$left)
  263. wmiir xwrite /tag/sel/ctl send sel left;;
  264. $modkey-Shift-$right)
  265. wmiir xwrite /tag/sel/ctl send sel right;;
  266. $modkey-Shift-$up)
  267. wmiir xwrite /tag/sel/ctl send sel up;;
  268. $modkey-Shift-$down)
  269. wmiir xwrite /tag/sel/ctl send sel down;;
  270. $modkey-Shift-space)
  271. wmiir xwrite /tag/sel/ctl send sel toggle;;
  272.  
  273. # Column Mode
  274. $modkey-d)
  275. wmiir xwrite /tag/sel/ctl colmode sel default-max;;
  276. $modkey-s)
  277. wmiir xwrite /tag/sel/ctl colmode sel stack-max;;
  278. $modkey-m)
  279. wmiir xwrite /tag/sel/ctl colmode sel stack+max;;
  280.  
  281. # Client Commands
  282. $modkey-Shift-c)
  283. wmiir xwrite /client/sel/ctl kill;;
  284. $modkey-f)
  285. wmiir xwrite /client/sel/ctl Fullscreen toggle;;
  286.  
  287. # Run program
  288. $modkey-Return)
  289. terminal &;;
  290. $modkey-p)
  291. eval exec wmiir setsid "$(proglist $PATH | wimenu -s 0)" &;;
  292. $modkey-a)
  293. {
  294. set -- $(proglist $actiondir | wimenu -s 0)
  295. echo $actiondir/$@
  296. eval exec $actiondir/$@
  297. } &;;
  298.  
  299. # Select view
  300. $modkey-t)
  301. # Prompt the user for a tag
  302. tag=$(wmiir ls /tag | sed 's,/,,; /^sel$/d' | wimenu -s 0)
  303. # Write it to the filesystem.
  304. wmiir xwrite /ctl view $tag;;
  305. $modkey-[0-9])
  306. # wmiir xwrite /ctl view ${1##*-};;
  307. tag=$(wmiir ls /tag | grep -v sel/ | tail -n +${1##*-} | head -n 1 | sed 's/\///')
  308. wmiir xwrite /ctl view $tag;;
  309.  
  310. # Tag client
  311. $modkey-Shift-t)
  312. # Prompt the user for new tags
  313. tag=$(wmiir ls /tag | sed 's,/,,; /^sel$/d' | wimenu -s 0)
  314. # Write them to the client
  315. wmiir xwrite /client/sel/tags $tag;;
  316. $modkey-Shift-[0-9])
  317. # wmiir xwrite /client/sel/tags ${1##*-};;
  318. tag=$(wmiir ls /tag | grep -v sel/ | tail -n +${1##*-} | head -n 1 | sed 's/\///')
  319. wmiir xwrite /client/sel/tags $tag;;
  320. esac;;
  321.  
  322. # Client menu
  323. ClientMouseDown) # ClientMouseDown <Client ID> <Button>
  324. case $2 in
  325. 3)
  326. clickmenu \
  327. "Delete:wmiir xwrite /client/$1/ctl kill" \
  328. "Remove:wmiir xwrite /client/$1/tags -$(wmiir read /tag/sel/ctl | head -n 1)" \
  329. "Kill:wmiir xwrite /client/$1/ctl slay";;
  330. 4)
  331. wmiir xwrite /tag/sel/ctl select up;;
  332. 5)
  333. wmiir xwrite /tag/sel/ctl select down;;
  334. esac;;
  335.  
  336. # Tag events
  337. LeftBarMouseDown) # LeftBarMouseDown <Button> <Bar Name>
  338. wmiir xwrite /ctl view $2;;
  339.  
  340. # Widget events
  341. RightBarMouseDown) # RightBarMouseDown <Button> <Bar Name>
  342. case $2 in # Which widget
  343.  
  344. mpd)
  345. case $1 in
  346. 1)
  347. mpc -q toggle
  348. mpd | wmiir write /rbar/mpd;;
  349. 3)
  350. terminal -e ncmpcpp &;;
  351. 4)
  352. mpc -q prev
  353. mpd | wmiir write /rbar/mpd;;
  354. 5)
  355. mpc -q next
  356. mpd | wmiir write /rbar/mpd;;
  357. esac;;
  358. vol)
  359. case $1 in # Which mouse button
  360. 1) # Left button
  361. amixer sset Master toggle
  362. vol | wmiir write /rbar/vol;;
  363. 4) # Scroll up
  364. amixer sset Master playback 2dB+
  365. vol | wmiir write /rbar/vol;;
  366. 5) # Scroll down
  367. amixer sset Master playback 2dB-
  368. vol | wmiir write /rbar/vol;;
  369. esac;;
  370.  
  371. mail)
  372. wmiir setsid icecat mail.mailserver.com &;;
  373.  
  374. zclock)
  375. terminal -hold -e cal -3 &;;
  376. esac;;
  377. esac
  378. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement