CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by pnd4 on Sat 2nd Feb 14:49 (modification of post by view diff)
download | new post

  1. #
  2. #              HILITES
  3. #              ruby script to display Weechat hilights in dzen.
  4. #              also beeps
  5. #
  6.  
  7. #
  8. #              Author: Christian Brassat, aka. crshd
  9. #              Email: christian@crshd.cc
  10. #
  11.  
  12. #              Modifications by pnd4
  13.  
  14. #
  15. # Copyright (c) 2011 Christian Brassat
  16. #
  17. # Permission is hereby granted, free of charge, to any person obtaining a copy
  18. # of this software and associated documentation files (the "Software"), to deal
  19. # in the Software without restriction, including without limitation the rights
  20. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  21. # copies of the Software, and to permit persons to whom the Software is
  22. # furnished to do so, subject to the following conditions:
  23. #
  24. # The above copyright notice and this permission notice shall be included in
  25. # all copies or substantial portions of the Software.
  26. #
  27. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  29. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  30. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  31. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  32. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  33. # THE SOFTWARE.
  34. #
  35.  
  36. #
  37. # USAGE:
  38. # First you need to create a FIFO file for the script to write to with
  39. # mkfifo $HOME/.weechat/pipe
  40. #
  41. # Then you can start dzen with something like this:
  42. # tail -f /home/crshd/.weechat/pipe | \
  43. # dzen2 -ta l -tw 145 -h 17 -l 6 -y 1280 -bg "#151515" -fn "Pragmata:size=8"
  44. #
  45.  
  46. # SETTINGS
  47. # To view the plugin's available options, run the following from within Weechat:
  48. # /set plugins.var.ruby.hilites.*
  49.  
  50. SCRIPT_NAME = 'hilites'
  51. SCRIPT_AUTHOR = 'Christian Brassat <christian@crshd.cc>'
  52. SCRIPT_DESC = 'Send highlights in channels to a named pipe'
  53. SCRIPT_VERSION = '0.2'
  54. SCRIPT_LICENSE = 'MIT'
  55.  
  56. DEFAULTS = {
  57.         'pipe_path'                    => "#{ENV['HOME']}/.weechat/pipe",
  58.         'beep_on_hilight'       => "true",
  59.         'beep_on_private' => "true",
  60.         'beep_file'                    => "#{ENV['HOME']}/.weechat/beep.ogg",
  61.         'color1'                                        => "435d65",
  62.         'color2'                                        => "6e98a4",
  63.         'color3'                                        => "2554a4",
  64.         'color4'                                        => "909090",
  65.         'color5'                                        => "606060",
  66.         'color6'                                        => "d92918"
  67. }
  68.  
  69. def weechat_init
  70.   Weechat.register SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""
  71.   DEFAULTS.each_pair { |option, def_value|
  72.     cur_value = Weechat.config_get_plugin(option)
  73.     if cur_value.nil? || cur_value.empty?
  74.       Weechat.config_set_plugin(option, def_value)
  75.     end
  76.   }
  77.         Weechat.hook_print("", "notify_message", "", 1, "hilite", "")
  78.   Weechat.hook_print("", "notify_private", "", 1, "private", "")
  79.  
  80.         return Weechat::WEECHAT_RC_OK
  81. end
  82.  
  83. def beep
  84.         IO.popen("mpg123 #{Weechat.config_get_plugin("beep_file")} 2>/dev/null")
  85. end
  86.  
  87. def hilite( data, buffer, date, tags, visible, highlight, prefix, message )
  88.  
  89.         if highlight == "1"
  90.  
  91.                 data = {}
  92.                 %w[ away type channel server ].each do |meta|
  93.                         data[ meta.to_sym ] = Weechat.buffer_get_string( buffer, "localvar_#{meta}" );
  94.                 end
  95.                 data[:away] = data[:away].empty? ? false : true
  96.  
  97.                 if data[:type] == "channel"
  98.                         timestamp = Time.at(date.to_i).strftime("%H:%M")
  99.  
  100.                         pipe = open( Weechat.config_get_plugin('pipe_path'), "w")
  101.                         pipe.printf("^tw()^fg(#%s) %s ^fg(#%s) %s \n %s ^fg(#%s)< %s > ^fg(#%s) %s ^fg(#%s) %s\n",
  102.                                 Weechat.config_get_plugin("color1"),
  103.                                 timestamp,
  104.                                 Weechat.config_get_plugin("color2"),
  105.                                 data[:channel],
  106.                                 timestamp,
  107.                                 Weechat.config_get_plugin("color3"),
  108.                                 prefix,
  109.                                 Weechat.config_get_plugin("color4"),
  110.                                 data[:channel],
  111.                                 Weechat.config_get_plugin("color5"),
  112.                                 message )
  113.                         pipe.close
  114.  
  115.                         beep if Weechat.config_get_plugin("beep_on_hilight") == "true"
  116.                 end
  117.         end
  118.  
  119.         return Weechat::WEECHAT_RC_OK
  120. end
  121.  
  122. def private( data, buffer, date, tags, visible, highlight, prefix, message )
  123.  
  124.         data = {}
  125.         %w[ away type channel server ].each do |meta|
  126.                 data[ meta.to_sym ] = Weechat.buffer_get_string( buffer, "localvar_#{meta}" );
  127.         end
  128.         data[:away] = data[:away].empty? ? false : true
  129.  
  130.         unless data[:channel] == data[:server]
  131.                 timestamp = Time.at(date.to_i).strftime("%H:%M")
  132.  
  133.                 pipe = open( Weechat.config_get_plugin('pipe_path'), "w")
  134.                 pipe.printf("^tw()^fg(#%s) %s ^fg(#%s) %s \n %s ^fg(#%s)< %s > ^fg(#%s) %s ^fg(#%s) %s\n",
  135.                         Weechat.config_get_plugin("color1"),
  136.                         timestamp,
  137.                         Weechat.config_get_plugin("color6"),
  138.                         data[:channel],
  139.                         timestamp,
  140.                         Weechat.config_get_plugin("color6"),
  141.                         data[:channel],
  142.                         Weechat.config_get_plugin("color4"),
  143.                         "Private Message",
  144.                         Weechat.config_get_plugin("color5"),
  145.                         message )
  146.                 pipe.close
  147.  
  148.                 beep if Weechat.config_get_plugin("beep_on_private") == "true"
  149.         end
  150.  
  151.         return Weechat::WEECHAT_RC_OK
  152. end
  153. #  vim: set ts=2 sw=2 tw=0 :

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me