Advertisement
Guest User

wmiirc

a guest
May 12th, 2011
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.87 KB | None | 0 0
  1. #!/bin/sh -f
  2.  
  3. up=k
  4. down=j
  5. left=h
  6. right=l
  7. modkey=Mod4
  8.  
  9. focuscolors='#000000 #cd6d37 #000000'
  10. normcolors='#000000 #848484 #000000'
  11.  
  12. font="xft:Sans-9"
  13.  
  14. wallpaper="/home/ben/pictures/wallpaper.png"
  15. feh --bg-tile $wallpaper &
  16.  
  17. actiondir="/home/ben/.wmii"
  18.  
  19. proglist() {
  20.     IFS=: set -- $1
  21.     find -L $@ -maxdepth 1 -perm /111 | sed '1d; s,.*/,,' | sort | uniq
  22.     unset IFS
  23. }
  24.  
  25. terminal() {
  26.     wmiir setsid urxvt "$@"
  27. }
  28.  
  29. clickmenu() {
  30.     if res=$(wmii9menu -- "$@"); then
  31.         eval "$res";
  32.     fi
  33. }
  34.  
  35. # Configure wmii
  36. wmiir write /ctl <<!
  37.     focuscolors $focuscolors
  38.     normcolors $normcolors
  39.     grabmod $modkey
  40.     border 1
  41.     view 1
  42.     bar on top
  43.     font $font
  44. !
  45.  
  46. # Create initial view
  47. echo $focuscolors 1 | wmiir create /lbar/1
  48.  
  49. # Create the notice bar
  50. echo $normcolors | wmiir create /rbar/!notice
  51.  
  52. # Right bar widgets
  53.  
  54. # Clock
  55. echo $normcolors clock | wmiir create /rbar/clock   # Create the widget
  56. clock() {
  57.     echo ◷ $(date '+%a %d, %b; %X')
  58. }
  59. while clock | wmiir write /rbar/clock; do
  60.     sleep 1
  61. done &
  62.  
  63. # MPD
  64. echo $normcolors mpd | wmiir create /rbar/mpd
  65. mpd() {
  66.   if [ `mpc status | grep playing | wc -l` -eq 1 ]; then
  67.     echo -n`mpc status | head -n 1`
  68.   else
  69.     if [ `mpc status | grep paused | wc -l` -eq 1 ]; then
  70.       echo -n ▮▮ `mpc status | head -n 1`
  71.     else
  72.       echo -n
  73.     fi
  74.   fi
  75. }
  76. while mpd | wmiir write /rbar/mpd; do
  77.     sleep 4
  78. done &
  79.  
  80. # Volume
  81. echo $normcolors vol | wmiir create /rbar/vol
  82. vol() {
  83.     echo ♪ $(aumix -q | grep vol | sed 's/vol [0-9]*, //' | sed 's/, P//') %
  84. }
  85. vol | wmiir write /rbar/vol
  86.  
  87. # Mail
  88. echo $normcolors mail | wmiir create /rbar/mail
  89. mail() {
  90.     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`
  91.  
  92.     if [ $unread -eq 0 ]; then
  93.         echo -n $normcolors$unread
  94.     else
  95.         echo -n $focuscolors$unread
  96.     fi
  97.  
  98. }
  99. while mail | wmiir write /rbar/mail; do
  100.     sleep 60
  101. done &
  102.  
  103. # Bind keys
  104. {
  105. cat <<!
  106. $modkey-$left
  107. $modkey-$right
  108. $modkey-$up
  109. $modkey-$down
  110. $modkey-space
  111. $modkey-Shift-$left
  112. $modkey-Shift-$right
  113. $modkey-Shift-$up
  114. $modkey-Shift-$down
  115. $modkey-Shift-space
  116. $modkey-d
  117. $modkey-s
  118. $modkey-m
  119. $modkey-Shift-c
  120. $modkey-f
  121. $modkey-Return
  122. $modkey-p
  123. $modkey-a
  124. !
  125. for i in 1 2 3 4 5 6 7 8 9 0; do
  126.     echo $modkey-$i
  127.     echo $modkey-Shift-$i
  128. done
  129. } | wmiir write /keys
  130.  
  131. # Open /event for reading
  132. wmiir read /event |
  133. # Read the events line by line
  134. while read line; do
  135.     set -- $line
  136.     event=$1; shift
  137.     line="$(echo $line | sed 's/^[^ ]* //' | tr -d '\n')"
  138.  
  139. #   echo ---------------------------------
  140. #   echo event: $event
  141. #   echo param1: $1
  142. #   echo param2: $2
  143.  
  144.     # Process the event
  145.     case $event in
  146.  
  147.     CreateTag)          # CreateTag <Tag Name>
  148.         echo $normcolors $1 | wmiir create /lbar/$1;;
  149.     DestroyTag)         # DestroyTag <Tag Name>
  150.         wmiir rm /lbar/$1;;
  151.     FocusTag)           # FocusTag <Tag Name>
  152.         wmiir xwrite /lbar/$1 $focuscolors $1;;
  153.     UnfocusTag)         # UnfocusTag <Tag Name>
  154.         wmiir xwrite /lbar/$1 $normcolors $1;;
  155.  
  156.     UrgentTag)          # UrgentTag <'Client' or 'Manager'> <Tag Name>
  157.         wmiir xwrite /lbar$2 $2;;
  158.     NotUrgentTag)           #NotUrgentTag <'Client' or 'Manager'> <TagName>
  159.         wmiir xwrite /lbar/$2 $2;;
  160.  
  161.     # Key Events
  162.     Key)                # Key <Key Name>
  163.         case $1 in
  164.         # Motion keys
  165.         $modkey-$left)
  166.             wmiir xwrite /tag/sel/ctl select left;;
  167.         $modkey-$right)
  168.             wmiir xwrite /tag/sel/ctl select right;;
  169.         $modkey-$up)
  170.             wmiir xwrite /tag/sel/ctl select up;;
  171.         $modkey-$down)
  172.             wmiir xwrite /tag/sel/ctl select down;;
  173.         $modkey-space)
  174.             wmiir xwrite /tag/sel/ctl select toggle;;
  175.  
  176.  
  177.         # Client movement
  178.         $modkey-Shift-$left)
  179.             wmiir xwrite /tag/sel/ctl send sel left;;
  180.         $modkey-Shift-$right)
  181.             wmiir xwrite /tag/sel/ctl send sel right;;
  182.         $modkey-Shift-$up)
  183.             wmiir xwrite /tag/sel/ctl send sel up;;
  184.         $modkey-Shift-$down)
  185.             wmiir xwrite /tag/sel/ctl send sel down;;
  186.         $modkey-Shift-space)
  187.             wmiir xwrite /tag/sel/ctl send sel toggle;;
  188.  
  189.         # Column Mode
  190.         $modkey-d)
  191.             wmiir xwrite /tag/sel/ctl colmode sel default-max;;
  192.         $modkey-s)
  193.             wmiir xwrite /tag/sel/ctl colmode sel stack-max;;
  194.         $modkey-m)
  195.             wmiir xwrite /tag/sel/ctl colmode sel stack+max;;
  196.  
  197.         # Client Commands
  198.         $modkey-Shift-c)
  199.             wmiir xwrite /client/sel/ctl kill;;
  200.         $modkey-f)
  201.             wmiir xwrite /client/sel/ctl Fullscreen toggle;;
  202.  
  203.         # Run program
  204.         $modkey-Return)
  205.             terminal &;;
  206.         $modkey-p)
  207.             eval exec wmiir setsid "$(proglist $PATH | wimenu -s 0)" &;;
  208.         $modkey-a)
  209.             {
  210.                 set -- $(proglist $actiondir | wimenu -s 0)
  211.                 echo $actiondir/$@
  212.                 eval exec $actiondir/$@
  213.             } &;;
  214.  
  215.         # Select view
  216.         $modkey-[0-9])
  217.             wmiir xwrite /ctl view ${1##*-};;
  218.         # Tag client
  219.         $modkey-Shift-[0-9])
  220.             wmiir xwrite /client/sel/tags ${1##*-};;
  221.         esac;;
  222.  
  223.     # Client menu
  224.     ClientMouseDown)        # ClientMouseDown <Client ID> <Button>
  225.         [ $2 = 3 ] && clickmenu \
  226.             "Delete:wmiir xwrite /client/$1/ctl kill" \
  227.             "Kill:wmiir xwrite /client/$1/ctl slay";;
  228.  
  229.     # Tag events
  230.     LeftBarMouseDown)       # LeftBarMouseDown <Button> <Bar Name>
  231.         wmiir xwrite /ctl view $2;;
  232.  
  233.     # Widget events
  234.     RightBarMouseDown)      # RightBarMouseDown <Button> <Bar Name>
  235.         case $2 in      # Which widget
  236.  
  237.         mpd)
  238.             case $1 in
  239.             1)
  240.                 mpc -q toggle
  241.                 mpd | wmiir write /rbar/mpd;;
  242.             3)
  243.                 terminal -e ncmpcpp &;;
  244.             4)
  245.                 mpc -q prev
  246.                 mpd | wmiir write /rbar/mpd;;
  247.             5)
  248.                 mpc -q next
  249.                 mpd | wmiir write /rbar/mpd;;
  250.             esac;;
  251.         vol)
  252.             case $1 in  # Which mouse button
  253.             1)      # Left button
  254.                 amixer sset Master toggle
  255.                 vol | wmiir write /rbar/vol;;
  256.             4)      # Scroll up
  257.                 amixer sset Master playback 2dB+
  258.                 vol | wmiir write /rbar/vol;;
  259.             5)      # Scroll down
  260.                 amixer sset Master playback 2dB-
  261.                 vol | wmiir write /rbar/vol;;
  262.             esac;;
  263.  
  264.         mail)
  265.             wmiir setsid firefox mail.google.com &;;
  266.  
  267.         clock)
  268.             terminal -hold -e cal -3 &;;
  269.         esac;;     
  270.     esac
  271. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement