Commit c84bcd21 authored by Nils Görs's avatar Nils Görs

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

parents 0cb77d2e 1cba393a
This diff is collapsed.
#
# 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
#
......@@ -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
......@@ -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 ]-------------------------------------
......@@ -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 ]-----------------------------------
......@@ -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);
}
......@@ -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".
......@@ -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"});
......@@ -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" ){
......@@ -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
}
This diff is collapsed.
#
# 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
......@@ -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
#
......@@ -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";
......@@ -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)',
);
......@@ -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];
......@@ -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;
......@@ -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
......@@ -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
......@@ -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');
......@@ -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;
}
......
# -*- 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', '')
......@@ -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
......@@ -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.'
......@@ -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):
......
This diff is collapsed.
This diff is collapsed.
......@@ -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
......@@ -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.")
......@@ -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 ":").
......@@ -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",
......@@ -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")
......@@ -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 = ""
......@@ -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.
# ----------------
......@@ -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:
......@@ -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", "")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment