Advertisement
bensmith87

wmiirc

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