Skip to content
Snippets Groups Projects
Commit c84bcd21 authored by Nils Görs's avatar Nils Görs
Browse files

Merge branch 'master' of https://github.com/weechat/scripts

parents 0cb77d2e 1cba393a
No related branches found
No related tags found
No related merge requests found
#
# Copyright (C) 2006-2012 Sebastien Helleu <flashcode@flashtux.org>
# Copyright (C) 2011 Nils Görs <weechatter@arcor.de>
# Copyright (C) 2011 ArZa <arza@arza.us>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Beep (terminal bell) and/or run command on highlight/private message or new DCC.
#
# History:
# 2012-06-05, ldvx<ldvx@freenode>:
# version 1.1: Added wildcard support for whitelist_nicks.
# 2012-05-09, ldvx <ldvx@freenode>:
# version 1.0: Added beep_pv_blacklist, beep_highlight_blacklist, blacklist_nicks,
# and wildcard support for blacklist_nicks.
# 2012-05-02, ldvx <ldvx@freenode>:
# version 0.9: fix regex for nick in tags, add options "whitelist_channels"
# and "bell_always"
# 2012-04-19, ldvx <ldvx@freenode>:
# version 0.8: add whitelist, trigger, use hook_process for commands,
# rename option "beep_command" to "beep_command_pv", add help for options
# 2011-04-16, ArZa <arza@arza.us>:
# version 0.7: fix default beep command
# 2011-03-11, nils_2 <weechatter@arcor.de>:
# version 0.6: add additional command options for dcc and highlight
# 2011-03-09, nils_2 <weechatter@arcor.de>:
# version 0.5: add option for beep command and dcc
# 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
# version 0.4: sync with last API changes
# 2008-11-05, Sebastien Helleu <flashcode@flashtux.org>:
# version 0.3: conversion to WeeChat 0.3.0+
# 2007-08-10, Sebastien Helleu <flashcode@flashtux.org>:
# version 0.2: upgraded licence to GPL 3
# 2006-09-02, Sebastien Helleu <flashcode@flashtux.org>:
# version 0.1: initial release
use strict;
my $SCRIPT_NAME = "beep";
my $VERSION = "1.1";
# default values in setup file (~/.weechat/plugins.conf)
my %options_default = ('beep_pv' => ['on', 'beep on private message'],
'beep_pv_whitelist' => ['off', 'turn whitelist for private messages on or off'],
'beep_pv_blacklist' => ['off', 'turn blacklist for private messages on or off'],
'beep_highlight' => ['on', 'beep on highlight'],
'beep_highlight_whitelist' => ['off', 'turn whitelist for highlights on or off'],
'beep_highlight_blacklist' => ['off', 'turn blacklist for highlights on or off'],
'beep_dcc' => ['on', 'beep on dcc'],
'beep_trigger_pv' => ['', 'word that will trigger execution of beep_command_pv (it empty, anything will trigger)'],
'beep_trigger_highlight' => ['', 'word that will trigger execution of beep_command_highlight (if empty, anything will trigger)'],
'beep_command_pv' => ['$bell', 'command for beep on private message, special value "$bell" is allowed, as well as "$bell;command"'],
'beep_command_highlight' => ['$bell', 'command for beep on highlight, special value "$bell" is allowed, as well as "$bell;command"'],
'beep_command_dcc' => ['$bell', 'command for beep on dcc, special value "$bell" is allowed, as well as "$bell;command"'],
'beep_command_timeout' => ['30000', 'timeout for command run (in milliseconds, 0 = never kill (not recommended))'],
'whitelist_nicks' => ['', 'comma-separated list of "server.nick": if not empty, only these nicks will trigger execution of commands (example: "freenode.nick1,freenode.nick2")'],
'blacklist_nicks' => ['', 'comma-separated list of "server.nick": if not empty, these nicks will not be able to trigger execution of commands. Cannot be used in conjuction with whitelist (example: "freenode.nick1,freenode.nick2")'],
'whitelist_channels' => ['', 'comma-separated list of "server.#channel": if not empty, only these channels will trigger execution of commands (example: "freenode.#weechat,freenode.#channel2")'],
'bell_always' => ['', 'use $bell on private messages and/or highlights regardless of trigger and whitelist settings (example: "pv,highlight")'],
);
my %options = ();
weechat::register($SCRIPT_NAME, "FlashCode <flashcode\@flashtux.org>", $VERSION,
"GPL3", "Beep (terminal bell) and/or run command on highlight/private message or new DCC", "", "");
init_config();
weechat::hook_config("plugins.var.perl.$SCRIPT_NAME.*", "toggle_config_by_set", "");
weechat::hook_print("", "", "", 1, "pv_and_highlight", "");
weechat::hook_signal("irc_dcc", "dcc", "");
sub pv_and_highlight
{
my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message) = @_;
# return if message is filtered
return weechat::WEECHAT_RC_OK if ($displayed != 1);
# return if nick in message is own nick
my $nick = "";
$nick = $2 if ($tags =~ m/(^|,)nick_([^,]*)(,|$)/);
return weechat::WEECHAT_RC_OK if (weechat::buffer_get_string($buffer, "localvar_nick") eq $nick);
# highlight
if ($highlight)
{
# Always print visual bel, regardless of whitelist and trigger settings
# beep_command_highlight does not need to contain $bell
if ($options{bell_always} =~ m/(^|,)highlight(,|$)/)
{
print STDERR "\a";
}
# Channels whitelist for highlights
if ($options{beep_highlight} eq "on")
{
if ($options{whitelist_channels} ne "")
{
my $serverandchannel = weechat::buffer_get_string($buffer, "localvar_server"). "." .
weechat::buffer_get_string($buffer, "localvar_channel");
if ($options{beep_trigger_highlight} eq "" or $message =~ m/\b$options{beep_trigger_highlight}\b/)
{
if ($options{whitelist_channels} =~ /(^|,)$serverandchannel(,|$)/)
{
beep_exec_command($options{beep_command_highlight});
}
# What if we are highlighted and we're in a PM? For now, do nothing.
}
}
else
{
# Execute $bell and/or command with trigger and whitelist/blacklist settings
beep_trigger_whitelist_blacklist($buffer, $message, $nick, $options{beep_trigger_highlight},
$options{beep_highlight_whitelist}, $options{beep_highlight_blacklist},
$options{beep_command_highlight});
}
}
}
# private message
elsif (weechat::buffer_get_string($buffer, "localvar_type") eq "private" and $tags =~ m/(^|,)notify_private(,|$)/)
{
# Always print visual bel, regardless of whitelist and trigger settings
# beep_command_pv does not need to contain $bell
if ($options{bell_always} =~ m/(^|,)pv(,|$)/)
{
print STDERR "\a";
}
# Execute $bell and/or command with trigger and whitelist/blacklist settings
if ($options{beep_pv} eq "on")
{
beep_trigger_whitelist_blacklist($buffer, $message, $nick, $options{beep_trigger_pv},
$options{beep_pv_whitelist}, $options{beep_pv_blacklist},
$options{beep_command_pv});
}
}
return weechat::WEECHAT_RC_OK;
}
sub dcc
{
beep_exec_command($options{beep_command_dcc}) if ($options{beep_dcc} eq "on");
return weechat::WEECHAT_RC_OK;
}
sub beep_trigger_whitelist_blacklist
{
my ($buffer, $message, $nick, $trigger, $whitelist, $blacklist, $command) = @_;
if ($trigger eq "" or $message =~ m/\b$trigger\b/)
{
my $serverandnick = weechat::buffer_get_string($buffer, "localvar_server").".".$nick;
if ($whitelist eq "on" and $options{whitelist_nicks} ne "")
{
# What to do if there's a wildcard in the whitelit
if ($options{whitelist_nicks} =~ m/\*/ and
match_in_wild_card($serverandnick, $options{whitelist_nicks}))
{
beep_exec_command($command);
}
# What to do if there's no wildcard in the whitelist
elsif ($options{whitelist_nicks} =~ /(^|,)$serverandnick(,|$)/)
{
beep_exec_command($command);
}
}
elsif ($blacklist eq "on" and $options{blacklist_nicks} ne "")
{
# What to do if there's a wildcard in the blacklist
if ($options{blacklist_nicks} =~ m/\*/ and
!match_in_wild_card($serverandnick, $options{blacklist_nicks}))
{
beep_exec_command($command);
}
# What to do if there's no wildcard in the blacklist
elsif ($options{blacklist_nicks} !~ /(^|,)$serverandnick(,|$)/)
{
beep_exec_command($command);
}
}
# What to do if we are not using whitelist of blacklist feature
elsif ($whitelist eq "off" and $blacklist eq "off")
{
beep_exec_command($command);
}
}
}
sub beep_exec_command
{
my $command = $_[0];
if ($command =~ /^\$bell/)
{
print STDERR "\a";
($command) = $command =~ /^\$bell;(.+)$/;
}
weechat::hook_process($command, $options{beep_command_timeout}, "my_process", "") if ($command);
}
sub match_in_wild_card
{
my ($serverandnick, $white_or_black) = @_;
my $nick_iter;
my @array_of_nicks = split(",", $white_or_black);
foreach $nick_iter (@array_of_nicks)
{
$nick_iter =~ s/\*/[^,]*/g;
if ($serverandnick =~ /$nick_iter/)
{
return 1;
}
}
return 0;
}
sub my_process
{
return weechat::WEECHAT_RC_OK;
}
sub toggle_config_by_set
{
my ($pointer, $name, $value) = @_;
$name = substr($name, length("plugins.var.perl.".$SCRIPT_NAME."."), length($name));
$options{$name} = $value;
return weechat::WEECHAT_RC_OK;
}
sub init_config
{
my $version = weechat::info_get("version_number", "") || 0;
foreach my $option (keys %options_default)
{
if (!weechat::config_is_set_plugin($option))
{
weechat::config_set_plugin($option, $options_default{$option}[0]);
$options{$option} = $options_default{$option}[0];
}
else
{
$options{$option} = weechat::config_get_plugin($option);
}
if ($version >= 0x00030500)
{
weechat::config_set_desc_plugin($option, $options_default{$option}[1]." (default: \"".$options_default{$option}[0]."\")");
}
}
}
#
# Copyright (c) 2010-2013 by Nils Görs <weechatter@arcor.de>
# Copyright (c) 2010-2018 by Nils Görs <weechatter@arcor.de>
#
# display the status and visited buffers of your buddies in a buddylist bar
#
Loading
Loading
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# 1.9 : added: cursor support
# 1.8 : fixed: problem with temporary server
# : added: %h variable for filename
# 1.7 : fixed: perl error when adding and removing nick
Loading
Loading
@@ -81,7 +82,7 @@
use strict;
 
my $prgname = "buddylist";
my $version = "1.8";
my $version = "1.9";
my $description = "display status from your buddies a bar-item.";
 
# -------------------------------[ config ]-------------------------------------
Loading
Loading
@@ -121,6 +122,9 @@ my %mouse_keys = ("\@item(buddylist):button1*"
"\@chat(*)>item(buddylist):button1-gesture-*" => "hsignal:buddylist_mouse",
"\@item(buddylist):button1-gesture-*" => "hsignal:buddylist_mouse");
 
my %cursor_keys = ( "\@item(buddylist):q" => "hsignal:buddylist_cursor",
"\@item(buddylist):w" => "hsignal:buddylist_cursor");
my $debug_redir_out = "off";
 
# ------------------------------[ internal ]-----------------------------------
Loading
Loading
@@ -196,7 +200,9 @@ weechat::hook_signal("upgrade_ended", "buddylist_upgrade_ended", "");
if ($weechat_version >= 0x00030600){
weechat::hook_focus($prgname, "hook_focus_buddylist", "");
weechat::hook_hsignal("buddylist_mouse","buddylist_hsignal_mouse", "");
weechat::hook_hsignal("buddylist_cursor","buddylist_hsignal_cursor", "");
weechat::key_bind("mouse", \%mouse_keys);
weechat::key_bind("cursor", \%cursor_keys);
}
 
 
Loading
Loading
@@ -248,10 +254,13 @@ weechat::hook_command($prgname, $description,
"\n".
"'plugins.var.perl.buddylist.use.redirection' : using redirection to get status of buddies (needs weechat >=0.3.4) (default: on).\n".
"\n\n".
"Mouse-support (standard key bindings):\n".
"Mouse-support:\n".
" click left mouse-button on buddy to open a query buffer.\n".
" add a buddy by dragging a nick with left mouse-button from nicklist or chat-area and drop on buddylist.\n".
" remove a buddy by dragging a buddy with left mouse-button from buddylist and drop it on any area.\n".
"Cursor-Mode:\n".
" q open query with nick (/query)\n".
" w query information about user (/whois)\n".
"\n\n".
"Troubleshooting:\n".
"If buddylist will not be refreshed in nicklist-mode, check the following WeeChat options:\n".
Loading
Loading
@@ -1521,7 +1530,7 @@ $server = $channel if ( $server eq "server");
 
return weechat::WEECHAT_RC_OK;
}
# -------------------------------[ mouse support ]-------------------------------------
# --------------------------[ mouse and cursor support ]--------------------------------
sub hook_focus_buddylist{
my %info = %{$_[1]};
my $bar_item_line = int($info{"_bar_item_line"});
Loading
Loading
@@ -1529,9 +1538,9 @@ sub hook_focus_buddylist{
return if ($#buddylist_focus == -1);
 
my $flag = 0;
# if button1 was pressed on "offline" buddy, do nothing!!!
if ( ($info{"_bar_item_name"} eq $prgname) && ($bar_item_line >= 0) && ($bar_item_line <= $#buddylist_focus) && ($info{"_key"} eq "button1" ) ){
$hash = $buddylist_focus[$bar_item_line];
# mouse or key pressed on "offline" buddy, do nothing!!!
if ( ($info{"_bar_item_name"} eq $prgname) && ($bar_item_line >= 0) && ($bar_item_line <= $#buddylist_focus) ){
$hash = $buddylist_focus[$bar_item_line];
my $hash_focus = $hash;
while ( my ($key,$value) = each %$hash_focus ){
if ( $key eq "status" and $value eq "2" ){
Loading
Loading
@@ -1574,4 +1583,20 @@ sub buddylist_hsignal_mouse{
weechat::bar_item_update($prgname);
return weechat::WEECHAT_RC_OK;
}
# this is the end
sub buddylist_hsignal_cursor{
my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
# no server?
return weechat::WEECHAT_RC_OK if (not defined $hash{"server"});
# check which key was pressed and do some magic!
if ( $hash{"_key"} eq "q" ){
weechat::command("", "/query -server " . $hash{"server"} . " " . $hash{"nick"});
}elsif ( $hash{"_key"} eq "w" ){
weechat::command(weechat::buffer_search("==","irc.server.".$hash{"server"}), "/WHOIS " . $hash{"nick"});
}
# STOP cursor mode
weechat::command("", "/cursor stop");
return weechat::WEECHAT_RC_OK;
}
# echo.pl by ArZa <arza@arza.us>: Print a line and additionally set activity level
# This program is free software: you can modify/redistribute it under the terms of
# GNU General Public License by Free Software Foundation, either version 3 or later
# which you can get from <http://www.gnu.org/licenses/>.
# This program is distributed in the hope that it will be useful, but without any warranty.
weechat::register("echo", "ArZa <arza\@arza.us>", "0.1", "GPL3", "Print a line and additionally set activity level", "", "");
weechat::hook_command(
"echo",
"Print a line and additionally set activity level. Local variables are expanded when starting with \$ and can be escaped with \\.",
"[ -p/-plugin <plugin> ] [ -b/-buffer <buffer name/number> | -c/-core ] [ -l/-level <level>] [text]",
"-plugin: plugin where printed, default: current plugin
-buffer: buffer where printed, default: current buffer, e.g. #weechat or freenode.#weechat)
-core: print to the core buffer
-level: number of the activity level, default: low:
0=low, 1=message, 2=private, 3=highlight
Examples:
/echo This is a test message
/echo -b freenode.#weechat -level 3 Highlight!
/echo -core This goes to the core buffer
/echo -buffer #weechat -l 1 My variable \\\$name is \$name on \$channel",
"-buffer %(buffer_names) || -core || -level 1|2|3 || -plugin %(plugins_names)", "echo", ""
);
sub echo {
my @args=split(/ /, $_[2]);
my $i=0;
my ($plugin, $buffer, $level) = ("", "", "");
while($i<=$#args){ # go through command options
if($args[$i] eq "-b" || $args[$i] eq "-buffer"){
$i++;
$buffer=$args[$i] if $args[$i];
}elsif($args[$i] eq "-p" || $args[$i] eq "-plugin"){
$i++;
$plugin=$args[$i] if $args[$i];
}elsif($args[$i] eq "-c" || $args[$i] eq "-core"){
$buffer=weechat::buffer_search_main();
}elsif($args[$i] eq "-l" || $args[$i] eq "-level"){
$i++;
$level=$args[$i] if $args[$i];
}else{
last;
}
$i++;
}
if($plugin ne ""){ # use specific plugin if set
$buffer=weechat::buffer_search($plugin, $buffer);
}elsif($buffer ne ""){
if($buffer=~/^\d+$/){ # if got a number
my $infolist = weechat::infolist_get("buffer", "", "");
while(weechat::infolist_next($infolist)){ # find the buffer for the number
if(weechat::infolist_integer($infolist, "number") eq $buffer){
$buffer=weechat::buffer_search( weechat::infolist_string($infolist, "plugin"), weechat::infolist_string($infolist, "name") );
last;
}
}
weechat::infolist_free($infolist);
}elsif( weechat::buffer_search ( weechat::buffer_get_string( weechat::current_buffer(), "plugin" ), $buffer ) ){ # if buffer found in current plugin
$buffer=weechat::buffer_search ( weechat::buffer_get_string( weechat::current_buffer(), "plugin" ), $buffer );
}else{ # search even more to find the correct buffer
my $infolist = weechat::infolist_get("buffer", "", "");
while(weechat::infolist_next($infolist)){ # find the buffer for a short_name
if(lc(weechat::infolist_string($infolist, "short_name")) eq lc($buffer)){
$buffer=weechat::buffer_search( weechat::infolist_string($infolist, "plugin"), weechat::infolist_string($infolist, "name") );
last;
}
}
weechat::infolist_free($infolist);
}
}
$buffer=weechat::current_buffer() if $buffer eq "" || $buffer eq $args[$i-1]; # otherwise use the current buffer
my $j=$i;
$args[$j]=~s/^\\\-/-/ if $args[$j]; # "\-" -> "-" in the beginning
while($j<=$#args){ # go through text
if($args[$j]=~/^\$/){ # replace variables
$args[$j]=weechat::buffer_string_replace_local_var($buffer, $args[$j]);
}elsif($args[$j]=~/^\\[\$\\]/){ # escape variables
$args[$j]=~s/^\\//;
}
$j++;
}
weechat::print($buffer, join(' ', @args[$i..$#args])); # print the text
weechat::buffer_set($buffer, "hotlist", $level); # set hotlist level
}
# Copyright (c) 2009-2010 by Nils Görs <weechatter@arcor.de>
# Copyright (c) 2009-2018 by Nils Görs <weechatter@arcor.de>
#
# waiting for hotlist to change and then execute a user specified command
# or writes the hotlist to screen title.
Loading
Loading
@@ -22,6 +22,7 @@
#
# Script inspirated and tested by LaoLang_cool
#
# 0.9 : add eval_expression() for format options
# 0.8 : escape special characters in hotlist (arza)
# 0.7 : using %h for weechat-dir instead of hardcoded path in script (flashcode)
# 0.6 : new option "use_title" to print hotlist in screen title.
Loading
Loading
@@ -32,69 +33,27 @@
# 0.3 : usersettings won't be loaded, sorry! :-(
# : added a more complex sort routine (from important to unimportant and also numeric)
# : added options: "delimiter", "priority_remove" and "hotlist_remove_format"
#
#
# use the following settings for hotlist_format:
# %h = weechat-dir (~/.weechat)
# %H = filled with highlight_char if a highlight message was written in channel. For example: *
# %N = filled with buffer number: 1 2 3 ....
# %S = filled with short name of channel: #weechat
#
# export the hotlist_format to your external command.
# %X
#
# Usage:
# template to use for display (for example: "1:freenode *2:#weechat"):
# /set plugins.var.perl.hotlist2extern.hotlist_format "%H%N:%S"
#
# Output (for example: "WeeChat Act: %H%N:%S"):
# /set plugins.var.perl.hotlist2extern.external_command_hotlist "echo WeeChat Act: %X >%h/hotlist_output.txt"
#
# Output if there is no activity (for example: "WeeChat: no activity"):
# /set plugins.var.perl.hotlist2extern.external_command_hotlist_empty "echo 'WeeChat: no activity ' >%h/hotlist_output.txt"
#
# charset for a highlight message:
# /set plugins.var.perl.hotlist2extern.highlight_char "*"
#
# template that shall be remove when message priority is low. (for example, the buffer name will be removed and only the buffer
# number will be display instead! (1 *2:#weechat):
# /set plugins.var.perl.hotlist2extern.hotlist_remove_format ":%S"
#
# message priority when using hotlist_remove_format (-1 means off)
# /set plugins.var.perl.hotlist2extern.priority_remove 0
#
# display messages with level:
# 0=crappy msg (join/part) and core buffer informations, 1=msg, 2=pv, 3=nick highlight
# /set plugins.var.perl.hotlist2extern.lowest_priority 0
#
# delimiter to use:
# /set plugins.var.perl.hotlist2extern.delimiter ","
#
# hotlist will be printed to screen title:
# /set plugins.var.perl.hotlist2extern.use_title "on"
 
use strict;
my $hotlist_format = "%H%N:%S";
my $hotlist_remove_format = ":%S";
my $external_command_hotlist = "echo WeeChat Act: %X >%h/hotlist_output.txt";
my $external_command_hotlist_empty = "echo \'WeeChat: no activity \' >%h/hotlist_output.txt";
my $highlight_char = "*";
my $lowest_priority = 0;
my $priority_remove = 0;
my $delimiter = ",";
my $use_title = "on";
my $prgname = "hotlist2extern";
my $version = "0.8";
my $description = "Give hotlist to an external file/program/screen title";
my $current_buffer = "";
my $SCRIPT_NAME = "hotlist2extern";
my $SCRIPT_VERSION = "0.9";
my $SCRIPT_DESC = "Give hotlist to an external file/program/screen title";
my $SCRIPT_AUTHOR = "Nils Görs <weechatter\@arcor.de>";
# default values
my %options = (
"hotlist_format" => "%H%N:%S",
"hotlist_remove_format" => ":%S",
"external_command_hotlist" => "echo WeeChat Act: %X >%h/hotlist_output.txt",
"external_command_hotlist_empty" => "echo \'WeeChat: no activity \' >%h/hotlist_output.txt",
"highlight_char" => "*",
"lowest_priority" => "0",
"priority_remove" => "0",
"delimiter" => ",",
"use_title" => "on",
);
 
my $plugin_name = "";
my $weechat_dir = "";
my $buffer_name = "";
my $buffer_number = 0;
my $buffer_pointer = 0;
my $short_name = "";
my $res = "";
my $res2 = "";
my $priority = 0;
Loading
Loading
@@ -106,36 +65,36 @@ my ($data, $buffer, $args) = ($_[0], $_[1], $_[2]); # save callback from hook_
@table = ();
$table = "";
 
$current_buffer = weechat::current_buffer; # get current buffer
my $current_buffer = weechat::current_buffer; # get current buffer
my $hotlist = weechat::infolist_get("hotlist","",""); # Pointer to Infolist
 
while (weechat::infolist_next($hotlist))
{
$priority = weechat::infolist_integer($hotlist, "priority");
$res = $hotlist_format; # save hotlist format
$res2 = $external_command_hotlist; # save external_hotlist format
$res = $options{hotlist_format}; # save hotlist format
$res2 = $options{external_command_hotlist}; # save external_hotlist format
 
$plugin_name = weechat::infolist_string($hotlist,"plugin_name");
$buffer_name = weechat::infolist_string($hotlist,"buffer_name");
$buffer_number = weechat::infolist_integer($hotlist,"buffer_number"); # get number of buffer
$buffer_pointer = weechat::infolist_pointer($hotlist, "buffer_pointer"); # Pointer to buffer
$short_name = weechat::buffer_get_string($buffer_pointer, "short_name"); # get short_name of buffer
my $plugin_name = weechat::infolist_string($hotlist,"plugin_name");
my $buffer_name = weechat::infolist_string($hotlist,"buffer_name");
my $buffer_number = weechat::infolist_integer($hotlist,"buffer_number"); # get number of buffer
my $buffer_pointer = weechat::infolist_pointer($hotlist, "buffer_pointer"); # Pointer to buffer
my $short_name = weechat::buffer_get_string($buffer_pointer, "short_name"); # get short_name of buffer
 
unless ($priority < $lowest_priority){
create_output();
unless ($priority < $options{lowest_priority}){
create_output($buffer_number, $short_name);
}
}
weechat::infolist_free($hotlist);
$table = @table;
if ($table eq 0){
unless ($external_command_hotlist_empty eq ""){ # does we have a command for empty string?
if ($use_title eq "on"){
weechat::window_set_title($external_command_hotlist_empty);
unless ($options{external_command_hotlist_empty} eq ""){ # does we have a command for empty string?
if ($options{use_title} eq "on"){
weechat::window_set_title(eval_expression($options{external_command_hotlist_empty}));
}else{
if (grep (/\%h/,$external_command_hotlist_empty)){ # does %h is in string?
$external_command_hotlist_empty =~ s/%h/$weechat_dir/; # add weechat-dir
if (grep (/\%h/,$options{external_command_hotlist_empty})){ # does %h is in string?
$options{external_command_hotlist_empty} =~ s/%h/$weechat_dir/; # add weechat-dir
}
system($external_command_hotlist_empty);
system(eval_expression($options{external_command_hotlist_empty}));
}
}
}
Loading
Loading
@@ -143,33 +102,34 @@ $table = "";
}
 
sub create_output{
$res = $hotlist_format; # save hotlist format
$res2 = $external_command_hotlist; # save external_hotlist format
my ($buffer_number, $short_name) = @_;
$res = eval_expression($options{hotlist_format}); # save hotlist format
$res2 = eval_expression($options{external_command_hotlist}); # save external_hotlist format
 
if ($priority == 3){ # priority is highlight
if (grep (/\%H/,$hotlist_format)){ # check with original!!!
$res =~ s/\%H/$highlight_char/g;
if (grep (/\%H/,$options{hotlist_format})){ # check with original!!!
$res =~ s/\%H/$options{highlight_char}/g;
}
}else{ # priority != 3
$res =~ s/\%H//g; # remove all %H
}
if ($priority <= $priority_remove){
$res =~ s/$hotlist_remove_format//; # remove hotlist_remove_format
if (grep (/\%S/,$hotlist_format)){ # does %S is in string? (check with original!!!)
if ($priority <= $options{priority_remove}){
$res =~ s/$options{hotlist_remove_format}//; # remove hotlist_remove_format
if (grep (/\%S/,$options{hotlist_format})){ # does %S is in string? (check with original!!!)
$res =~ s/%S/$short_name/; # add short_name
}
if (grep (/\%N/,$hotlist_format)){
if (grep (/\%N/,$options{hotlist_format})){
$res =~ s/%N/$buffer_number/; # add buffer_number
}
}else{
if (grep (/\%S/,$hotlist_format)){ # does %S is in string? (check with original!!!)
if (grep (/\%S/,$options{hotlist_format})){ # does %S is in string? (check with original!!!)
$res =~ s/%S/$short_name/; # add short_name
}
if (grep (/\%N/,$hotlist_format)){
if (grep (/\%N/,$options{hotlist_format})){
$res =~ s/%N/$buffer_number/; # add buffer_number
}
}
if ($res ne $hotlist_format and $res ne ""){ # did $res changed?
if ($res ne $options{hotlist_format} and $res ne ""){ # did $res changed?
my $res2 = $res; # save search string.
$res2=qq(\Q$res2); # kill metachars, for searching first
unless (grep /^$res2$/, @table){ # does we have added $res to @table?
Loading
Loading
@@ -179,16 +139,16 @@ sub create_output{
 
$res=qq(\Q$res); # kill metachars first
if (grep /^$res$/, @table){ # does we have added $res to @table?
my $export = join("$delimiter", sort_routine(@table));
my $export = join("$options{delimiter}", sort_routine(@table));
$export = qq(\Q$export); # escape special characters
if (grep (/\%X/,$external_command_hotlist)){ # check for %X option.
if (grep (/\%X/,$options{external_command_hotlist})){ # check for %X option.
$res2 =~ s/%X/$export/;
 
if (grep (/\%h/,$external_command_hotlist)){ # does %h is in string?
if (grep (/\%h/,$options{external_command_hotlist})){ # does %h is in string?
$res2 =~ s/%h/$weechat_dir/; # add weechat-dir
}
 
if ($use_title eq "on"){
if ($options{use_title} eq "on"){
weechat::window_set_title($res2);
}else{
system($res2);
Loading
Loading
@@ -199,7 +159,7 @@ sub create_output{
}
 
# first sort channels with highlight, then channels with
# action and the rest will be put it at the end of list
# action and the rest will be placed at the end of list
sub sort_routine {
my @zeilen = @_;
my @sortiert = map { $_->[0] }
Loading
Loading
@@ -214,102 +174,60 @@ sub _extern{
return weechat::WEECHAT_RC_OK;
}
 
sub init{
# set value of script (for example starting script the first time)
if (!weechat::config_is_set_plugin("external_command_hotlist")){
weechat::config_set_plugin("external_command_hotlist", $external_command_hotlist);
}else{
$external_command_hotlist = weechat::config_get_plugin("external_command_hotlist");
}
if (!weechat::config_is_set_plugin("external_command_hotlist_empty")){
weechat::config_set_plugin("external_command_hotlist_empty", $external_command_hotlist_empty);
}else{
$external_command_hotlist_empty = weechat::config_get_plugin("external_command_hotlist_empty");
}
if (!weechat::config_is_set_plugin("highlight_char")){
weechat::config_set_plugin("highlight_char", $highlight_char);
}else{
$highlight_char = weechat::config_get_plugin("highlight_char");
}
if (!weechat::config_is_set_plugin("lowest_priority")){
weechat::config_set_plugin("lowest_priority", $lowest_priority);
}else{
$lowest_priority = weechat::config_get_plugin("lowest_priority");
}
if (!weechat::config_is_set_plugin("hotlist_format")){
weechat::config_set_plugin("hotlist_format", $hotlist_format);
}else{
$hotlist_format = weechat::config_get_plugin("hotlist_format");
}
if (!weechat::config_is_set_plugin("hotlist_remove_format")){
weechat::config_set_plugin("hotlist_remove_format", $hotlist_remove_format);
}else{
$hotlist_remove_format = weechat::config_get_plugin("hotlist_remove_format");
}
if (!weechat::config_is_set_plugin("priority_remove")){
weechat::config_set_plugin("priority_remove", $priority_remove);
}else{
$priority_remove = weechat::config_get_plugin("priority_remove");
}
if (!weechat::config_is_set_plugin("delimiter")){
weechat::config_set_plugin("delimiter", $delimiter);
}else{
$delimiter = weechat::config_get_plugin("delimiter");
}
if (!weechat::config_is_set_plugin("use_title")){
weechat::config_set_plugin("use_title", $use_title);
}else{
$use_title = weechat::config_get_plugin("use_title");
}
$weechat_dir = weechat::info_get("weechat_dir", "");
sub eval_expression{
my ( $string ) = @_;
$string = weechat::string_eval_expression($string, {}, {},{});
return $string;
}
 
sub toggle_config_by_set{
my ( $pointer, $name, $value ) = @_;
sub init_config{
foreach my $option(keys %options){
if (!weechat::config_is_set_plugin($option)){
weechat::config_set_plugin($option, $options{$option});
}
else{
$options{$option} = weechat::config_get_plugin($option);
}
}
}
 
if ($name eq "plugins.var.perl.$prgname.external_command_hotlist"){
$external_command_hotlist = $value;
return weechat::WEECHAT_RC_OK;
}
if ($name eq "plugins.var.perl.$prgname.external_command_hotlist_empty"){
$external_command_hotlist_empty = $value;
return weechat::WEECHAT_RC_OK;
}
if ($name eq "plugins.var.perl.$prgname.highlight_char"){
$highlight_char = $value;
return weechat::WEECHAT_RC_OK;
}
if ($name eq "plugins.var.perl.$prgname.lowest_priority"){
$lowest_priority = $value;
return weechat::WEECHAT_RC_OK;
}
if ($name eq "plugins.var.perl.$prgname.hotlist_format"){
$hotlist_format = $value;
return weechat::WEECHAT_RC_OK;
}
if ($name eq "plugins.var.perl.$prgname.hotlist_remove_format"){
$hotlist_remove_format = $value;
return weechat::WEECHAT_RC_OK;
}
if ($name eq "plugins.var.perl.$prgname.priority_remove"){
$priority_remove = $value;
return weechat::WEECHAT_RC_OK;
}
if ($name eq "plugins.var.perl.$prgname.delimiter"){
$delimiter = $value;
return weechat::WEECHAT_RC_OK;
}
if ($name eq "plugins.var.perl.$prgname.use_title"){
$use_title = $value;
sub toggle_config_by_set{
my ( $pointer, $name, $value ) = @_;
$name = substr($name,length("plugins.var.perl.$SCRIPT_NAME."),length($name));
$options{$name} = $value;
return weechat::WEECHAT_RC_OK;
}
}
 
# first function called by a WeeChat-script.
weechat::register($prgname, "Nils Görs <weechatter\@arcor.de>", $version,
"GPL3", $description, "", "");
init(); # get user settings
weechat::hook_signal("hotlist_changed", "hotlist_changed", "");
weechat::hook_config( "plugins.var.perl.$prgname.*", "toggle_config_by_set", "" );
weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION,
"GPL3", $SCRIPT_DESC, "", "");
weechat::hook_command($SCRIPT_NAME, $SCRIPT_DESC,
"",
"This script allows you to export the hotlist to a file or screen title.\n".
"use the following intern variables for the hotlist_format:\n".
" %h = weechat-dir (~/.weechat), better use \${info:weechat_dir}\n".
" %H = replaces with highlight_char, if a highlight message was received. For example: *\n".
" %N = replaces with buffer number: 1 2 3 ....\n".
" %S = replaces with short name of channel: #weechat\n".
" %X = export the whole hotlist_format to your external command.\n".
"\n".
"configure script with: /fset plugins.var.perl.hotlist2extern\n".
"print hotlist to screen title: plugins.var.perl.hotlist2extern.use_title\n".
"delimiter to use : plugins.var.perl.hotlist2extern.delimiter\n".
"charset for highlight message: plugins.var.perl.hotlist2extern.highlight_char\n".
"message priority for hotlist_remove_format (-1 means off): plugins.var.perl.hotlist2extern.priority_remove\n".
"display messages level : plugins.var.perl.hotlist2extern.lowest_priority\n".
"following options are evaluated:\n".
"template for display : plugins.var.perl.hotlist2extern.hotlist_format\n".
"template for low priority : plugins.var.perl.hotlist2extern.hotlist_remove_format\n".
"Output format : plugins.var.perl.hotlist2extern.external_command_hotlist\n".
"Output format 'no activity' : plugins.var.perl.hotlist2extern.external_command_hotlist_empty\n".
"",
"", "", "");
init_config(); # /set
$weechat_dir = weechat::info_get("weechat_dir", "");
weechat::hook_signal("hotlist_changed", "hotlist_changed", "");
weechat::hook_config( "plugins.var.perl.$SCRIPT_NAME.*", "toggle_config_by_set", "" );
#
# Copyright (c) 2013-2014 by Nils Görs <weechatter@arcor.de>
# Copyright (c) 2013-2018 by Nils Görs <weechatter@arcor.de>
# Copyright (c) 2013-2014 by Stefan Wold <ratler@stderr.eu>
# based on irssi script stalker.pl from Kaitlyn Parkhurst (SymKat) <symkat@symkat.com>
# https://github.com/symkat/Stalker
Loading
Loading
@@ -20,6 +20,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# History:
# version 1.6.1:nils_2@freenode.#weechat
# 2018-01-11: fix: wrong variable name
#
# version 1.6:nils_2@freenode.#weechat
# 2018-01-09: add: use hook_process_hashtable() for /WHOIS
# : imp: use hook_process_hashtable() instead hook_process() for security reasons
#
# version 1.5:nils_2@freenode.#weechat
# 2015-06-15: add: new option del_date
#
Loading
Loading
@@ -101,7 +108,7 @@ use File::Spec;
use DBI;
 
my $SCRIPT_NAME = "stalker";
my $SCRIPT_VERSION = "1.5";
my $SCRIPT_VERSION = "1.6.1";
my $SCRIPT_AUTHOR = "Nils Görs <weechatter\@arcor.de>";
my $SCRIPT_LICENCE = "GPL3";
my $SCRIPT_DESC = "Records and correlates nick!user\@host information";
Loading
Loading
@@ -148,7 +155,7 @@ my %desc_options = ('db_name' => 'file containing the SQLite database
'ignore_whois' => 'When enabled, /WHOIS won\'t be monitored. (default: off)',
'tags' => 'comma separated list of tags used for messages printed by stalker. See documentation for possible tags (e.g. \'no_log\', \'no_highlight\'). This option does not effect DEBUG messages.',
'additional_join_info' => 'add a line below the JOIN message that will display alternative nicks (tags: "irc_join", "irc_smart_filter" will be add to additional_join_info). You can use a localvar to drop additional join info for specific buffer(s) "stalker_drop_additional_join_info" (default: off)',
'timeout' => 'timeout in seconds for hook_process(), used with option "additional_join_info". On slower machines, like raspberry pi, increase time. (default: 1)',
'timeout' => 'timeout in seconds for hook_process_hashtable(), used with option "additional_join_info". On slower machines, like raspberry pi, increase time. (default: 1)',
'flood_timer' => 'Time in seconds for which flood protection is active. Once max_nicks is reached, joins will be ignored for the remaining duration of the timer. (default:10)',
'flood_max_nicks' => 'Maximum number of joins to allow in flood_timer length of time. Once maximum number of joins is reached, joins will be ignored until the timer ends (default:20)',
);
Loading
Loading
@@ -181,7 +188,7 @@ my %indices = (
],
);
 
# ---------------[ external routines for hook_process() ]---------------------
# ---------------[ external routines for hook_process_hashtable() ]---------------------
if ($#ARGV == 8 ) # (0-8) nine arguments given?
{
my $db_filename = $ARGV[0];
Loading
Loading
@@ -515,7 +522,7 @@ sub add_record
my ( $nick, $user, $host, $serv ) = @_;
return unless ($nick and $user and $host and $serv);
 
# Check if we already have this record, before using a hook_process()
# Check if we already have this record, before using a hook_process_hashtable()
my $sth = $DBH_child->prepare( "SELECT nick FROM records WHERE nick = ? AND user = ? AND host = ? AND serv = ?" );
$sth->execute( $nick, $user, $host, $serv );
my $result = $sth->fetchrow_hashref;
Loading
Loading
@@ -533,7 +540,22 @@ sub add_record
 
my $db_filename = weechat_dir();
DEBUG("info", "Start hook_process(), to add $nick $user\@$host on $serv to database");
weechat::hook_process("perl $filename $db_filename 'db_add_record' '$nick' '$user' '$host' '$serv' 'dummy' 'dummy' 'dummy'", 1000 * $options{'timeout'},"db_add_record_cb","");
weechat::hook_process_hashtable("perl",
{
"arg1" => $filename,
"arg2" => $db_filename,
"arg3" => 'db_add_record',
"arg4" => $nick,
"arg5" => $user,
"arg6" => $host,
"arg7" => $serv,
"arg8" => 'dummy',
"arg9" => 'dummy',
"arg10" => 'dummy',
}, 1000 * $options{'timeout'},"db_add_record_cb","");
}
 
# function called when data from child is available, or when child has ended, arguments and return value
Loading
Loading
@@ -1102,7 +1124,6 @@ sub irc_in2_whois_cb
my (undef, undef, undef, $nick, $user, $host, undef) = split(' ', $callback_data);
my $msgbuffer_whois = weechat::config_string(weechat::config_get('irc.msgbuffer.whois'));
 
DEBUG('info', 'weechat_hook_signal(): WHOIS');
 
# check for nick_regex
Loading
Loading
@@ -1144,11 +1165,32 @@ sub irc_in2_whois_cb
}
 
my $use_regex = 0;
my $nicks_found = join( ", ", (get_nick_records('yes', 'nick', $nick, $server, $use_regex)));
# my $nicks_found = join( ", ", (get_nick_records('no', 'nick', $nick, $server, $use_regex)));
my $filename = get_script_filename();
return weechat::WEECHAT_RC_OK if ($filename eq "");
 
my $db_filename = weechat_dir();
my $name = weechat::buffer_get_string($ptr_buffer,'localvar_name');
DEBUG("info", "Start hook_process(), get additional for WHOIS() info from $nick with $user\@$host on $name");
weechat::hook_process_hashtable("perl",
{
"arg1" => $filename,
"arg2" => $db_filename,
"arg3" => 'additional_join_info',
"arg4" => $nick,
"arg5" => $user,
"arg6" => $host,
"arg7" => $server,
"arg8" => $options{'max_recursion'},
"arg9" => $options{'ignore_guest_nicks'},
"arg10" => $options{'guest_nick_regex'},
}, 1000 * $options{'timeout'},"hook_process_get_nicks_records_cb","$nick $ptr_buffer 'dummy'");
# my $nicks_found = join( ", ", (get_nick_records('yes', 'nick', $nick, $server, $use_regex)));
return weechat::WEECHAT_RC_OK;
# only the given nick is returned?
return weechat::WEECHAT_RC_OK if ($nicks_found eq $nick or $nicks_found eq "");
# return weechat::WEECHAT_RC_OK if ($nicks_found eq $nick or $nicks_found eq "");
 
# more than one nick was returned from sqlite
my $prefix_network = weechat::prefix('network');
Loading
Loading
@@ -1259,7 +1301,21 @@ sub irc_in2_join_cb
 
my $db_filename = weechat_dir();
DEBUG("info", "Start hook_process(), get additional info from $nick with $user\@$host on $name");
weechat::hook_process("perl $filename $db_filename 'additional_join_info' '$nick' '$user' '$host' '$server' $options{'max_recursion'} $options{'ignore_guest_nicks'} '$options{'guest_nick_regex'}'", 1000 * $options{'timeout'},"hook_process_get_nicks_records_cb","$nick $buffer $my_tags");
weechat::hook_process_hashtable("perl",
{
"arg1" => $filename,
"arg2" => $db_filename,
"arg3" => 'additional_join_info',
"arg4" => $nick,
"arg5" => $user,
"arg6" => $host,
"arg7" => $server,
"arg8" => $options{'max_recursion'},
"arg9" => $options{'ignore_guest_nicks'},
"arg10" => $options{'guest_nick_regex'},
}, 1000 * $options{'timeout'},"hook_process_get_nicks_records_cb","$nick $buffer $my_tags");
}
return weechat::WEECHAT_RC_OK;
}
Loading
Loading
# -*- coding: utf-8 -*-
#
# Copyright (c) 2011-2013 by F. Besser <fbesser@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# History:
# 2013-09-01, nils_2@freenode.#weechat:
# version 0.2: add support of servername for "-exclude"
# : make script behave like /allchan and /allserver command
# : add function "-current"
# : case-insensitive search for query/server
#
# 2011-09-05, F. Besser <fbesser@gmail.com>:
# version 0.1: script created
#
# Development is on:
# https://github.com/fbesser/weechat_scripts
#
# (this script requires WeeChat 0.3.0 or newer)
#
SCRIPT_NAME = "allquery"
SCRIPT_AUTHOR = "fbesser"
SCRIPT_VERSION = "0.2"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Executes command on all irc query buffer"
SCRIPT_COMMAND = "allquery"
import_ok = True
try:
import weechat
except ImportError:
print('This script must be run under WeeChat.')
print('Get WeeChat now at: http://www.weechat.org/')
import_ok = False
try:
import re
except ImportError, message:
print('Missing package(s) for %s: %s' % (SCRIPT_NAME, message))
import_ok = False
def make_list(argument):
""" Make a list out of argument string of format -argument=value0,value1"""
arglist = argument.lower().split("=", 1)
arguments = arglist[1].split(",")
return arguments
def allquery_command_cb(data, buffer, args):
""" Callback for /allquery command """
args = args.strip()
if args == "":
weechat.command("", "/help %s" % SCRIPT_COMMAND)
return weechat.WEECHAT_RC_OK
argv = args.split(" ")
exclude_nick = None
current_server = None
if '-current' in argv:
current_server = weechat.buffer_get_string(weechat.current_buffer(), "localvar_server")
# remove "-current" + whitespace from argumentlist
args = args.replace("-current", "")
args = args.lstrip()
argv.remove("-current")
# search for "-exclude" in arguments
i = 0
for entry in argv[0:]:
if entry.startswith("-exclude="):
exclude_nick = make_list(argv[i])
command = " ".join(argv[i+1::])
break
i +=1
else:
command = args
# no command found.
if not command:
return weechat.WEECHAT_RC_OK
if not command.startswith("/"):
command = "/%s" % command
infolist = weechat.infolist_get("buffer", "", "")
while weechat.infolist_next(infolist):
if weechat.infolist_string(infolist, "plugin_name") == "irc":
ptr = weechat.infolist_pointer(infolist, "pointer")
server = weechat.buffer_get_string(ptr, "localvar_server")
query = weechat.buffer_get_string(ptr, "localvar_channel")
execute_command = re.sub(r'\$nick', query, command)
if weechat.buffer_get_string(ptr, "localvar_type") == "private":
if current_server is not None:
if server == current_server:
exclude_nick_and_server(ptr,query,server,exclude_nick,execute_command)
else:
exclude_nick_and_server(ptr,query,server,exclude_nick,execute_command)
weechat.infolist_free(infolist)
return weechat.WEECHAT_RC_OK
def exclude_nick_and_server(ptr, query, server, exclude_nick, execute_command):
server = "%s.*" % server # servername + ".*"
if exclude_nick is not None:
if not query.lower() in exclude_nick and not server.lower() in exclude_nick:
weechat.command(ptr, execute_command)
else:
weechat.command(ptr, execute_command)
if __name__ == '__main__' and import_ok:
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
weechat.hook_command(SCRIPT_COMMAND, SCRIPT_DESC,
'[-current] [-exclude=<nick|server>[,<nick2|server>...]] <command> [<arguments>]',
' -current: execute command for query of current server only\n'
' -exclude: exclude some querys and/or server from executed command\n'
' command: command executed in query buffers\n'
' arguments: arguments for command (special variables $nick will be replaced by its value)\n\n'
'Examples:\n'
' close all query buffers:\n'
' /' + SCRIPT_COMMAND + ' buffer close\n'
' close all query buffers, but don\'t close FlashCode:\n'
' /' + SCRIPT_COMMAND + ' -exclude=FlashCode buffer close\n'
' close all query buffers, except for server freenode:\n'
' /' + SCRIPT_COMMAND + ' -exclude=freenode.* buffer close\n'
' msg to all query buffers:\n'
' /' + SCRIPT_COMMAND + ' say Hello\n'
' notice to all query buffers:\n'
' /' + SCRIPT_COMMAND + ' notice $nick Hello',
'%(commands)',
'allquery_command_cb', '')
Loading
Loading
@@ -21,6 +21,8 @@
History:
* 2017-03-22, Ricky Brent <ricky@rickybrent.com>:
version 0.1: initial release
* 2018-03-02, Brady Trainor <mail@bradyt.com>:
version 0.2: fix the merge command
"""
 
from __future__ import print_function
Loading
Loading
@@ -32,7 +34,7 @@ except ImportError:
print('Script must be run under weechat. http://www.weechat.org')
IMPORT_OK = False
 
VERSION = '0.1'
VERSION = '0.2'
NAME = 'automerge'
AUTHOR = 'Ricky Brent <ricky@rickybrent.com>'
DESC = 'Merge new irc buffers according to defined rules.'
Loading
Loading
@@ -93,7 +95,7 @@ def cb_signal_apply_rules(data, signal, buf):
if re.match(pattern, name):
mid = find_merge_id(buf, merge)
if mid >= 0:
weechat.command(buf, "/merge " + str(mid))
weechat.command(buf, "/buffer merge " + str(mid))
return weechat.WEECHAT_RC_OK
 
def cb_command(data, buf, args):
Loading
Loading
# -*- coding: utf-8 -*-
# =============================================================================
# shell.py (c) March 2006, 2009 by Kolter <kolter@openics.org>
#
# Licence : GPL v2
# Description : running shell commands in WeeChat
# Syntax : try /help shell to get some help on this script
# Precond : needs weechat >= 0.3.0 to run
#
#
# ### changelog ###
#
# * version 0.8, 2013-07-27, Sebastien Helleu <flashcode@flashtux.org>:
# - don't remove empty lines in output of command
# * version 0.7, 2012-11-26, Sebastien Helleu <flashcode@flashtux.org>:
# - use hashtable for command arguments (for WeeChat >= 0.4.0)
# * version 0.6, 2012-11-21, Sebastien Helleu <flashcode@flashtux.org>:
# - call shell in hook_process (WeeChat >= 0.3.9.2 does not call shell any more)
# * version 0.5, 2011-10-01, Sebastien Helleu <flashcode@flashtux.org>:
# - add shell buffer
# * version 0.4, 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
# - sync with last API changes
# * version 0.3, 2009-03-06, Sebastien Helleu <flashcode@flashtux.org>:
# - use of hook_process to run background process
# - add option -t <timeout> to kill process after <timeout> seconds
# - show process running, kill it with -kill
# * version 0.2, 2009-01-31, Sebastien Helleu <flashcode@flashtux.org>:
# - conversion to WeeChat 0.3.0+
# * version 0.1, 2006-03-13, Kolter <kolter@openics.org>:
# - first release
#
# =============================================================================
import weechat, os, datetime
SCRIPT_NAME = 'shell'
SCRIPT_AUTHOR = 'Kolter'
SCRIPT_VERSION = '0.8'
SCRIPT_LICENSE = 'GPL2'
SCRIPT_DESC = 'Run shell commands in WeeChat'
SHELL_CMD = 'shell'
SHELL_PREFIX = '[shell] '
cmd_hook_process = ''
cmd_command = ''
cmd_start_time = None
cmd_buffer = ''
cmd_shell_buffer = ''
cmd_stdout = ''
cmd_stderr = ''
cmd_send_to_buffer = ''
cmd_timeout = 0
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
SCRIPT_DESC, '', ''):
weechat.hook_command(
SHELL_CMD,
'Running shell commands in WeeChat',
'[-o|-n] [-t seconds] <command> || -show || -kill',
' -o: send output to current buffer (simulate user entry '
'with command output - dangerous, be careful when using this option)\n'
' -n: display output in a new empty buffer\n'
'-t seconds: auto-kill process after timeout (seconds) if process '
'is still running\n'
' command: shell command or builtin like cd, getenv, setenv, unsetenv\n'
' -show: show running process\n'
' -kill: kill running process',
'-o|-n|-t|cd|getenv|setenv|unsetenv|-show||-kill -o|-n|-t|cd|getenv|setenv|unsetenv',
'shell_cmd', '')
def shell_init():
"""Initialize some variables."""
global cmd_hook_process, cmd_command, cmd_start_time, cmd_buffer, cmd_stdout, cmd_stderr
cmd_hook_process = ''
cmd_command = ''
cmd_start_time = None
cmd_buffer = ''
cmd_stdout = ''
cmd_stderr = ''
def shell_set_title():
"""Set title on shell buffer (with working directory)."""
global cmd_shell_buffer
if cmd_shell_buffer:
weechat.buffer_set(cmd_shell_buffer, 'title',
'%s.py %s | "q": close buffer | Working dir: %s' % (SCRIPT_NAME, SCRIPT_VERSION, os.getcwd()))
def shell_process_cb(data, command, rc, stdout, stderr):
"""Callback for hook_process()."""
global cmd_hook_process, cmd_buffer, cmd_stdout, cmd_stderr, cmd_send_to_buffer
cmd_stdout += stdout
cmd_stderr += stderr
if int(rc) >= 0:
if cmd_stdout:
lines = cmd_stdout.rstrip().split('\n')
if cmd_send_to_buffer == 'current':
for line in lines:
weechat.command(cmd_buffer, '%s' % line)
else:
weechat.prnt(cmd_buffer, '')
if cmd_send_to_buffer != 'new':
weechat.prnt(cmd_buffer, '%sCommand "%s" (rc %d), stdout:'
% (SHELL_PREFIX, data, int(rc)))
for line in lines:
weechat.prnt(cmd_buffer, ' \t%s' % line)
if cmd_stderr:
lines = cmd_stderr.rstrip().split('\n')
if cmd_send_to_buffer == 'current':
for line in lines:
weechat.command(cmd_buffer, '%s' % line)
else:
weechat.prnt(cmd_buffer, '')
if cmd_send_to_buffer != 'new':
weechat.prnt(cmd_buffer, '%s%sCommand "%s" (rc %d), stderr:'
% (weechat.prefix('error'), SHELL_PREFIX, data, int(rc)))
for line in lines:
weechat.prnt(cmd_buffer, '%s%s' % (weechat.prefix('error'), line))
cmd_hook_process = ''
shell_set_title()
return weechat.WEECHAT_RC_OK
def shell_show_process(buffer):
"""Show running process."""
global cmd_command, cmd_start_time
if cmd_hook_process:
weechat.prnt(buffer, '%sprocess running: "%s" (started on %s)'
% (SHELL_PREFIX, cmd_command, cmd_start_time.ctime()))
else:
weechat.prnt(buffer, '%sno process running' % SHELL_PREFIX)
def shell_kill_process(buffer):
"""Kill running process."""
global cmd_hook_process, cmd_command
if cmd_hook_process:
weechat.unhook(cmd_hook_process)
weechat.prnt(buffer, '%sprocess killed (command "%s")' % (SHELL_PREFIX, cmd_command))
shell_init()
else:
weechat.prnt(buffer, '%sno process running' % SHELL_PREFIX)
def shell_chdir(buffer, directory):
"""Change working directory."""
if not directory:
if os.environ.has_key('HOME'):
directory = os.environ['HOME']
try:
os.chdir(directory)
except:
weechat.prnt(buffer, '%san error occured while running command "cd %s"' % (SHELL_PREFIX, directory))
else:
weechat.prnt(buffer, '%schdir to "%s" ok, new path: %s' % (SHELL_PREFIX, directory, os.getcwd()))
shell_set_title()
def shell_getenv(buffer, var):
"""Get environment variable."""
global cmd_send_to_buffer
var = var.strip()
if not var:
weechat.prnt(buffer, '%swrong syntax, try "getenv VAR"' % (SHELL_PREFIX))
return
value = os.getenv(var)
if value == None:
weechat.prnt(buffer, '%s$%s is not set' % (SHELL_PREFIX, var))
else:
if cmd_send_to_buffer == 'current':
weechat.command(buffer, '$%s=%s' % (var, os.getenv(var)))
else:
weechat.prnt(buffer, '%s$%s=%s' % (SHELL_PREFIX, var, os.getenv(var)))
def shell_setenv(buffer, expr):
"""Set an environment variable."""
global cmd_send_to_buffer
expr = expr.strip()
lexpr = expr.split('=')
if (len(lexpr) < 2):
weechat.prnt(buffer, '%swrong syntax, try "setenv VAR=VALUE"' % (SHELL_PREFIX))
return
os.environ[lexpr[0].strip()] = '='.join(lexpr[1:])
if cmd_send_to_buffer != 'current':
weechat.prnt(buffer, '%s$%s is now set to "%s"' % (SHELL_PREFIX, lexpr[0], '='.join(lexpr[1:])))
def shell_unsetenv(buffer, var):
"""Remove environment variable."""
var = var.strip()
if not var:
weechat.prnt(buffer, '%swrong syntax, try "unsetenv VAR"' % (SHELL_PREFIX))
return
if os.environ.has_key(var):
del os.environ[var]
weechat.prnt(buffer, '%s$%s is now unset' % (SHELL_PREFIX, var))
else:
weechat.prnt(buffer, '%s$%s is not set' % (SHELL_PREFIX, var))
def shell_exec(buffer, command):
"""Execute a command."""
global cmd_hook_process, cmd_command, cmd_start_time, cmd_buffer
global cmd_stdout, cmd_stderr, cmd_send_to_buffer, cmd_timeout
if cmd_hook_process:
weechat.prnt(buffer,
'%sanother process is running! (use "/%s -kill" to kill it)'
% (SHELL_PREFIX, SHELL_CMD))
return
if cmd_send_to_buffer == 'new':
weechat.prnt(buffer, '-->\t%s%s$ %s%s'
% (weechat.color('chat_buffer'), os.getcwd(), weechat.color('reset'), command))
weechat.prnt(buffer, '')
args = command.split(' ')
if args[0] == 'cd':
shell_chdir(buffer, ' '.join(args[1:]))
elif args[0] == 'getenv':
shell_getenv (buffer, ' '.join(args[1:]))
elif args[0] == 'setenv':
shell_setenv (buffer, ' '.join(args[1:]))
elif args[0] == 'unsetenv':
shell_unsetenv (buffer, ' '.join(args[1:]))
else:
shell_init()
cmd_command = command
cmd_start_time = datetime.datetime.now()
cmd_buffer = buffer
version = weechat.info_get("version_number", "") or 0
if int(version) >= 0x00040000:
cmd_hook_process = weechat.hook_process_hashtable('sh', { 'arg1': '-c', 'arg2': command },
cmd_timeout * 1000, 'shell_process_cb', command)
else:
cmd_hook_process = weechat.hook_process("sh -c '%s'" % command, cmd_timeout * 1000, 'shell_process_cb', command)
def shell_input_buffer(data, buffer, input):
"""Input callback on shell buffer."""
global cmd_send_to_buffer
if input in ('q', 'Q'):
weechat.buffer_close(buffer)
return weechat.WEECHAT_RC_OK
cmd_send_to_buffer = 'new'
weechat.prnt(buffer, '')
command = weechat.string_input_for_buffer(input)
shell_exec(buffer, command)
return weechat.WEECHAT_RC_OK
def shell_close_buffer(data, buffer):
"""Close callback on shell buffer."""
global cmd_shell_buffer
cmd_shell_buffer = ''
return weechat.WEECHAT_RC_OK
def shell_new_buffer():
"""Create shell buffer."""
global cmd_shell_buffer
cmd_shell_buffer = weechat.buffer_search('python', 'shell')
if not cmd_shell_buffer:
cmd_shell_buffer = weechat.buffer_new('shell', 'shell_input_buffer', '', 'shell_close_buffer', '')
if cmd_shell_buffer:
shell_set_title()
weechat.buffer_set(cmd_shell_buffer, 'localvar_set_no_log', '1')
weechat.buffer_set(cmd_shell_buffer, 'time_for_each_line', '0')
weechat.buffer_set(cmd_shell_buffer, 'input_get_unknown_commands', '1')
weechat.buffer_set(cmd_shell_buffer, 'display', '1')
return cmd_shell_buffer
def shell_cmd(data, buffer, args):
"""Callback for /shell command."""
global cmd_send_to_buffer, cmd_timeout
largs = args.split(' ')
# strip spaces
while '' in largs:
largs.remove('')
while ' ' in largs:
largs.remove(' ')
cmdbuf = buffer
if len(largs) == 0:
shell_new_buffer()
else:
if largs[0] == '-show':
shell_show_process(cmdbuf)
elif largs[0] == '-kill':
shell_kill_process(cmdbuf)
else:
cmd_send_to_buffer = ''
cmd_timeout = 0
while largs:
if largs[0] == '-o':
cmd_send_to_buffer = 'current'
largs = largs[1:]
continue
if largs[0] == '-n':
cmd_send_to_buffer = 'new'
cmdbuf = shell_new_buffer()
largs = largs[1:]
continue
if largs[0] == '-t' and len(largs) > 2:
cmd_timeout = int(largs[1])
largs = largs[2:]
continue
break
if len(largs) > 0:
shell_exec(cmdbuf, ' '.join(largs))
return weechat.WEECHAT_RC_OK
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Loading
Loading
@@ -25,7 +25,10 @@ import csv
import os
import re
import subprocess
from StringIO import StringIO
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
import time
 
import weechat
Loading
Loading
@@ -36,7 +39,7 @@ import weechat
 
SCRIPT_NAME = "vimode"
SCRIPT_AUTHOR = "GermainZ <germanosz@gmail.com>"
SCRIPT_VERSION = "0.5"
SCRIPT_VERSION = "0.5.1"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = ("Add vi/vim-like modes and keybindings to WeeChat.")
 
Loading
Loading
@@ -50,7 +53,7 @@ SCRIPT_DESC = ("Add vi/vim-like modes and keybindings to WeeChat.")
# Halp! Halp! Halp!
GITHUB_BASE = "https://github.com/GermainZ/weechat-vimode/blob/master/"
README_URL = GITHUB_BASE + "README.md"
FAQ_KEYBINDINGS = GITHUB_BASE + "FAQ#problematic-key-bindings.md"
FAQ_KEYBINDINGS = GITHUB_BASE + "FAQ.md#problematic-key-bindings"
FAQ_ESC = GITHUB_BASE + "FAQ.md#esc-key-not-being-detected-instantly"
 
# Holds the text of the command-line mode (currently only Ex commands ":").
Loading
Loading
@@ -778,14 +781,16 @@ VI_KEYS = {'j': "/window scroll_down",
'I': key_I,
'yy': key_yy,
'p': "/input clipboard_paste",
'/': "/input search_text",
'gt': "/buffer +1",
'K': "/buffer +1",
'gT': "/buffer -1",
'J': "/buffer -1",
'/': "/input search_text_here",
'gt': "/buffer -1",
'K': "/buffer -1",
'gT': "/buffer +1",
'J': "/buffer +1",
'r': key_r,
'R': key_R,
'~': key_tilda,
'nt': "/bar scroll nicklist * -100%",
'nT': "/bar scroll nicklist * +100%",
'\x01[[A': "/input history_previous",
'\x01[[B': "/input history_next",
'\x01[[C': "/input move_next_char",
Loading
Loading
@@ -980,7 +985,8 @@ def cb_key_combo_default(data, signal, signal_data):
# This is to avoid crashing WeeChat on script reloads/unloads,
# because no hooks must still be running when a script is
# reloaded or unloaded.
if VI_KEYS[vi_keys] == "/input return":
if (VI_KEYS[vi_keys] == "/input return" and
input_line.startswith("/script ")):
return weechat.WEECHAT_RC_OK
weechat.command("", VI_KEYS[vi_keys])
current_cur = weechat.buffer_get_integer(buf, "input_pos")
Loading
Loading
@@ -1124,6 +1130,7 @@ def cb_exec_cmd(data, remaining_calls):
weechat.command("", "/cursor go {},{}".format(x, y))
# Check againt defined commands.
else:
raw_data = data
data = data.split(" ", 1)
cmd = data[0]
args = ""
Loading
Loading
@@ -1131,11 +1138,22 @@ def cb_exec_cmd(data, remaining_calls):
args = data[1]
if cmd in VI_COMMANDS:
weechat.command("", "%s %s" % (VI_COMMANDS[cmd], args))
# No vi commands defined, run the command as a WeeChat command.
else:
# Check for commands not sepearated by space (e.g. "b2")
for i in range(1, len(raw_data)):
tmp_cmd = raw_data[:i]
tmp_args = raw_data[i:]
if tmp_cmd in VI_COMMANDS and tmp_args.isdigit():
weechat.command("", "%s %s" % (VI_COMMANDS[tmp_cmd],
tmp_args))
return weechat.WEECHAT_RC_OK
# No vi commands found, run the command as WeeChat command
weechat.command("", "/{} {}".format(cmd, args))
return weechat.WEECHAT_RC_OK
 
def cb_vimode_go_to_normal(data, buf, args):
set_mode("NORMAL")
return weechat.WEECHAT_RC_OK
 
# Script commands.
# ----------------
Loading
Loading
@@ -1409,7 +1427,7 @@ if __name__ == "__main__":
print_warning("Please upgrade to WeeChat ≥ 1.0.0. Previous versions"
" are not supported.")
# Set up script options.
for option, value in vimode_settings.items():
for option, value in list(vimode_settings.items()):
if weechat.config_is_set_plugin(option):
vimode_settings[option] = weechat.config_get_plugin(option)
else:
Loading
Loading
@@ -1444,3 +1462,6 @@ if __name__ == "__main__":
" --list: only list changes",
"help || bind_keys |--list",
"cb_vimode_cmd", "")
weechat.hook_command("vimode_go_to_normal", ("This command can be used for"
" key bindings to go to normal mode."), "", "", "",
"cb_vimode_go_to_normal", "")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment