weechat

- me personal weechat setup 🔵🟢
git clone git://git.acid.vegas/weechat.git
Log | Files | Refs | Archive | README

perlexec.pl (1965B)

      1 # perlexec.pl by ArZa <arza@arza.us>: Execute perl code
      2 
      3 # This program is free software: you can modify/redistribute it under the terms of
      4 # GNU General Public License by Free Software Foundation, either version 3 or later
      5 # which you can get from <http://www.gnu.org/licenses/>.
      6 # This program is distributed in the hope that it will be useful, but without any warranty.
      7 
      8 weechat::register("perlexec", "ArZa <arza\@arza.us>", "0.1", "GPL3", "Execute perl code", "", "");
      9 weechat::hook_command("perlexec", "Execute perl code", "[code]",
     10                       "Executes perl code given as an argument or creates a buffer for execution if not given an argument.\n\n".
     11                       "Code is anything like in a weechat perl script, executed in one block.\n\n".
     12                       "\$buffer is predefined as a pointer for the buffer where this command is executed.\n\n".
     13                       "For example, close current buffer if it's a query:\n".
     14                       "  /perlexec weechat::buffer_close(\$buffer) if weechat::buffer_get_string(\$buffer, \"localvar_type\") eq \"private\";",
     15                       "", "perlexec", "");
     16 
     17 sub perlexec { # the command
     18   if($_[2]){ # if got an argument
     19     my $buffer=$_[1];
     20     eval($_[2]); # execute
     21   }else{
     22     my $buffer=weechat::buffer_search("perl", "perlexec"); # find the buffer
     23     if(!$buffer){ # if not found
     24       $buffer=weechat::buffer_new("perlexec", "buffer_input", "", "", ""); # create it
     25       weechat::buffer_set($buffer, "title", "Perl execution buffer"); # set title
     26     }
     27     if(weechat::current_buffer() eq $buffer){ weechat::buffer_close($buffer); } # if we already are in the buffer, close it
     28     else{ weechat::buffer_set($buffer, "display", 1); } # otherwise, switch to it
     29   }
     30   return weechat::WEECHAT_RC_OK;
     31 }
     32 
     33 sub buffer_input { # input in the buffer
     34   my $buffer=$_[1];
     35   weechat::print($buffer, "> ".$_[2]); # print
     36   eval($_[2]); # execute
     37   return weechat::WEECHAT_RC_OK;
     38 }