scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

pastie.pl (1258B)


      1 use strict;
      2 
      3 my $SCRIPT_NAME = "pastie";
      4 
      5 weechat::register("pastie", "cipher <haris\@2f30.org>", "0.1", "Public Domain", "Paste output", "", "");
      6 weechat::hook_command("pastie", "Just select your text with the cursor, and \"/pastie\" in your window.
      7 By default, it uses \"xsel -o\" to output X selection.
      8 
      9 If you want another application for output, you can set it for example with:
     10 
     11   /set plugins.var.perl.pastie.ext_command \"xsel -o\"
     12 
     13 Replace \"xsel -o\" with your program of choice.
     14 ----------------------------------------------", "", "", "", "pastie", "");
     15 
     16 my $pastie_command;
     17 
     18 init_config();
     19 
     20 sub init_config {
     21   my %options = (
     22                   "ext_command" => "xsel -o",
     23   );
     24   foreach my $option (keys %options) {
     25     weechat::config_set_plugin($option, $options{$option}) unless weechat::config_is_set_plugin($option);
     26   }
     27 }
     28 
     29 sub pastie {
     30   my ($data, $command, $return_code, $out, $err) = @_;
     31   my $buffer = $data;
     32   $pastie_command = weechat::config_get_plugin("ext_command");
     33   my @output = `$pastie_command`;
     34 
     35   weechat::command($buffer, ",--<--");
     36 
     37   foreach my $output (@output) {
     38     $output =~ s/(.*?)\t/  /g;
     39     weechat::command($buffer, "| $output");
     40   }
     41 
     42   weechat::command($buffer, "`-->--");
     43   return weechat::WEECHAT_RC_OK;
     44 }