bensmith87

wmiirc

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