update weechat scripts

master
Ben Harris 2019-10-23 20:49:15 -04:00
parent 756dbd8397
commit 0eebd01222
9 changed files with 192 additions and 175 deletions

@ -1 +1 @@
Subproject commit 315e568de006e80138f79c77d5508c7e4853e6b2 Subproject commit 0c6c76e08115d0ba160e2c95c8692e4174aa5368

View File

@ -14,5 +14,4 @@ instant = on
timer = 1 timer = 1
[buffer] [buffer]
irc.freenode.#thunix.hotlist_max_level_nicks_add = "Bender:2"
irc.tilde.#trivia.hotlist_max_level_nicks_add = "Oz:2,Nerd:2" irc.tilde.#trivia.hotlist_max_level_nicks_add = "Oz:2,Nerd:2"

View File

@ -106,6 +106,7 @@ whois_double_nick = off
whois = current whois = current
[ctcp] [ctcp]
pronouns = "he/him"
[ignore] [ignore]
@ -153,10 +154,10 @@ usermode = ""
username = "${env:USER}" username = "${env:USER}"
[server] [server]
tilde.addresses = "localhost" tilde.addresses = "gingko.tilde.chat/6697"
tilde.proxy tilde.proxy
tilde.ipv6 tilde.ipv6
tilde.ssl = off tilde.ssl = on
tilde.ssl_cert tilde.ssl_cert
tilde.ssl_priorities tilde.ssl_priorities
tilde.ssl_dhkey_size tilde.ssl_dhkey_size
@ -179,9 +180,9 @@ tilde.username
tilde.realname tilde.realname
tilde.local_hostname tilde.local_hostname
tilde.usermode tilde.usermode
tilde.command = "/oper root ${sec.data.tildenetoper}; /msg operserv login ${sec.data.pass}" tilde.command = "/msg operserv login ${sec.data.pass}"
tilde.command_delay tilde.command_delay
tilde.autojoin = "#chaos,#meta,#opers,#secret-sudoers,#team,#sudoers,#yourtilde,#music,#politics,#gopher,#tildeverse,#idlerpg,#tilderadio,#minecraft,#tildelinux,#cosmic,#institute,#.tilde,#tildetel,#thunix,#theasylum,#minetest,#aussie,#uucp,#projects,#hamradio,#vim,#black,#pink,#~,#netnews,#admin,#bots,#ctrl-c,#bitbot,#radiofreqs,#brains,#envs,#rfcs,#best :57:60,:10:20" tilde.autojoin = "#meta,#secret-sudoers,#opers,#sudoers,#yourtilde,#music,#politics,#gopher,#tildeverse,#idlerpg,#tilderadio,#minecraft,#tildelinux,#cosmic,#institute,#.tilde,#tildetel,#thunix,#theasylum,#minetest,#aussie,#uucp,#projects,#hamradio,#vim,#black,#pink,#~,#netnews,#admin,#bots,#ctrl-c,#bitbot,#radiofreqs,#brains,#envs,#rfcs,#best,#wilde,#tildegames,#theasylum-admins,#tildenet,#gemini,#club,#zine,#twtxt,#factorio,#team,#summit :10:20,secretsudoteam"
tilde.autorejoin tilde.autorejoin
tilde.autorejoin_delay tilde.autorejoin_delay
tilde.connection_timeout tilde.connection_timeout
@ -304,7 +305,7 @@ esper.local_hostname
esper.usermode esper.usermode
esper.command esper.command
esper.command_delay esper.command_delay
esper.autojoin = "#lobby,#coders 10:30" esper.autojoin = "#lobby,#coders,#factorio 10:30"
esper.autorejoin esper.autorejoin
esper.autorejoin_delay esper.autorejoin_delay
esper.connection_timeout esper.connection_timeout
@ -440,7 +441,7 @@ oftc.msg_part
oftc.msg_quit oftc.msg_quit
oftc.notify oftc.notify
oftc.split_msg_max_length oftc.split_msg_max_length
freenode.addresses = "irc.freenode.net/6697" freenode.addresses = "irc.us.freenode.net/6697"
freenode.proxy freenode.proxy
freenode.ipv6 freenode.ipv6
freenode.ssl = on freenode.ssl = on
@ -468,7 +469,7 @@ freenode.local_hostname
freenode.usermode freenode.usermode
freenode.command freenode.command
freenode.command_delay freenode.command_delay
freenode.autojoin = "#weechat,##oodnet,#lobsters,#lobsters-boil,#gitea,#mastodon,#pleroma,#pleroma-offtopic,#oragono,#weechat-android,#git,#tilde.team,#sr.ht,#cmpwn,#gopherproject,#bitreich-en,#bitbot,#bitreich-de,#ircv3,#gophernicus,##jan6,##ircv3-offtopic,#ovh,#elixir-lang,#ascii.town,#sonarr,#lxcontainers 6:10" freenode.autojoin = "#weechat,##oodnet,#lobsters,#lobsters-boil,#gitea,#mastodon,#pleroma,#pleroma-offtopic,#oragono,#weechat-android,#git,#tilde.team,#sr.ht,#cmpwn,#gopherproject,#bitreich-en,#bitbot,#bitreich-de,#ircv3,#gophernicus,##jan6,##ircv3-offtopic,#ovh,#elixir-lang,#ascii.town,#sonarr,#lxcontainers,#thelounge,#indieweb,#indieweb-dev,#indieweb-meta,#indieweb-chat,#knownchat,#NetBSD,#cjdns,##ircv3-chat,#mumble,#!,#tildeclub,#freenode,#stutter,#futel 6:10"
freenode.autorejoin freenode.autorejoin
freenode.autorejoin_delay freenode.autorejoin_delay
freenode.connection_timeout freenode.connection_timeout
@ -591,7 +592,7 @@ slashnet.local_hostname
slashnet.usermode slashnet.usermode
slashnet.command slashnet.command
slashnet.command_delay slashnet.command_delay
slashnet.autojoin = "#gtlug,#mefi" slashnet.autojoin = "#gtlug"
slashnet.autorejoin slashnet.autorejoin
slashnet.autorejoin_delay slashnet.autorejoin_delay
slashnet.connection_timeout slashnet.connection_timeout
@ -686,44 +687,85 @@ red.msg_part
red.msg_quit red.msg_quit
red.notify red.notify
red.split_msg_max_length red.split_msg_max_length
ascii.addresses = "ascii.town/6697" hackint.addresses = "irc.hackint.org/6697"
ascii.proxy hackint.proxy
ascii.ipv6 hackint.ipv6
ascii.ssl = on hackint.ssl = on
ascii.ssl_cert hackint.ssl_cert
ascii.ssl_priorities hackint.ssl_priorities
ascii.ssl_dhkey_size hackint.ssl_dhkey_size
ascii.ssl_fingerprint hackint.ssl_fingerprint
ascii.ssl_verify hackint.ssl_verify
ascii.password hackint.password
ascii.capabilities hackint.capabilities
ascii.sasl_mechanism hackint.sasl_mechanism
ascii.sasl_username hackint.sasl_username = "benharri"
ascii.sasl_password hackint.sasl_password = "${sec.data.pass}"
ascii.sasl_key hackint.sasl_key
ascii.sasl_timeout hackint.sasl_timeout
ascii.sasl_fail hackint.sasl_fail
ascii.autoconnect hackint.autoconnect
ascii.autoreconnect hackint.autoreconnect
ascii.autoreconnect_delay hackint.autoreconnect_delay
ascii.nicks hackint.nicks = "benharri"
ascii.nicks_alternate hackint.nicks_alternate
ascii.username hackint.username
ascii.realname hackint.realname
ascii.local_hostname hackint.local_hostname
ascii.usermode hackint.usermode
ascii.command hackint.command
ascii.command_delay hackint.command_delay
ascii.autojoin = "&town" hackint.autojoin = "#tildeverse,#hackint,#36c3,#camp"
ascii.autorejoin hackint.autorejoin
ascii.autorejoin_delay hackint.autorejoin_delay
ascii.connection_timeout hackint.connection_timeout
ascii.anti_flood_prio_high hackint.anti_flood_prio_high
ascii.anti_flood_prio_low hackint.anti_flood_prio_low
ascii.away_check hackint.away_check
ascii.away_check_max_nicks hackint.away_check_max_nicks
ascii.msg_kick hackint.msg_kick
ascii.msg_part hackint.msg_part
ascii.msg_quit hackint.msg_quit
ascii.notify hackint.notify
ascii.split_msg_max_length hackint.split_msg_max_length
efnet.addresses = "irc.servercentral.net"
efnet.proxy
efnet.ipv6
efnet.ssl
efnet.ssl_cert
efnet.ssl_priorities
efnet.ssl_dhkey_size
efnet.ssl_fingerprint
efnet.ssl_verify
efnet.password
efnet.capabilities
efnet.sasl_mechanism
efnet.sasl_username
efnet.sasl_password
efnet.sasl_key
efnet.sasl_timeout
efnet.sasl_fail
efnet.autoconnect
efnet.autoreconnect
efnet.autoreconnect_delay
efnet.nicks
efnet.nicks_alternate
efnet.username
efnet.realname
efnet.local_hostname
efnet.usermode
efnet.command
efnet.command_delay
efnet.autojoin = "#dragonflybsd,#freebsd"
efnet.autorejoin
efnet.autorejoin_delay
efnet.connection_timeout
efnet.anti_flood_prio_high
efnet.anti_flood_prio_low
efnet.away_check
efnet.away_check_max_nicks
efnet.msg_kick
efnet.msg_part
efnet.msg_quit
efnet.notify
efnet.split_msg_max_length

View File

@ -69,7 +69,7 @@ python.buffer_autoclose.age_limit = "30"
python.buffer_autoclose.ignore = "" python.buffer_autoclose.ignore = ""
python.buffer_autoclose.interval = "1" python.buffer_autoclose.interval = "1"
python.check_license = "off" python.check_license = "off"
python.completion.replace_values = "shrug=>¯\_(ツ)_/¯;;wiki=>https://tilde.team/wiki/;;sword=>o()xxxx[{::::::::::::::::::::::::::::::::::>;;lenny=>( ͡° ͜ʖ ͡°);;byobu=>https://superuser.com/a/423397/866501;;huh=>(-_-)ゞ゛;;tablefix=>┬─┬ノ( º _ ºノ);;weedoc=>https://weechat.org/files/doc/stable/weechat_user.en.html;;weekeys=>https://weechat.org/files/doc/stable/weechat_user.en.html#key_bindings;;denko=>(´・ω・`);;yuno=>ლ(́ಠ◞益◟ಠ‵ლ);;tf=>(ノಥ益ಥ)ノ彡┻━┻;;tb=>┬─┬ノ( º _ ºノ);;ducc=>・゜゜・。。・゜゜\_o< QUACK!" python.completion.replace_values = "shrug=>¯\_(ツ)_/¯;;wiki=>https://tilde.team/wiki/;;sword=>o()xxxx[{::::::::::::::::::::::::::::::::::>;;lenny=>( ͡° ͜ʖ ͡°);;byobu=>https://superuser.com/a/423397/866501;;fg=>(☞゚ヮ゚)☞;;huh=>(-_-)ゞ゛;;tablefix=>┬─┬ノ( º _ ºノ);;weedoc=>https://weechat.org/files/doc/stable/weechat_user.en.html;;weekeys=>https://weechat.org/files/doc/stable/weechat_user.en.html#key_bindings;;denko=>(´・ω・`);;yuno=>ლ(́ಠ◞益◟ಠ‵ლ);;tf=>(ノಥ益ಥ)ノ彡┻━┻;;tb=>┬─┬ノ( º _ ºノ);;ducc=>・゜゜・。。・゜゜\_o< QUACK!"
python.go.auto_jump = "off" python.go.auto_jump = "off"
python.go.buffer_number = "on" python.go.buffer_number = "on"
python.go.color_name = "black,cyan" python.go.color_name = "black,cyan"

View File

@ -48,7 +48,10 @@
# #
# 2018-08-09, Julien Palard <julien@palard.fr> # 2018-08-09, Julien Palard <julien@palard.fr>
# version 0.3.0: Support for Python 3 # version 0.3.0: Support for Python 3
#
# 2019-09-28, fructose
# version 0.3.1: Error on invalid arguments
#
# @TODO: add options to ignore certain buffers # @TODO: add options to ignore certain buffers
# @TODO: maybe add an option to enable autosaving on part/join messages # @TODO: maybe add an option to enable autosaving on part/join messages
@ -57,7 +60,7 @@ import re
SCRIPT_NAME = "autojoin" SCRIPT_NAME = "autojoin"
SCRIPT_AUTHOR = "xt <xt@bash.no>" SCRIPT_AUTHOR = "xt <xt@bash.no>"
SCRIPT_VERSION = "0.3.0" SCRIPT_VERSION = "0.3.1"
SCRIPT_LICENSE = "GPL3" SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Configure autojoin for all servers according to currently joined channels" SCRIPT_DESC = "Configure autojoin for all servers according to currently joined channels"
SCRIPT_COMMAND = "autojoin" SCRIPT_COMMAND = "autojoin"
@ -86,6 +89,7 @@ for option, default_value in settings.items():
if w.config_get_plugin(option) == "": if w.config_get_plugin(option) == "":
w.config_set_plugin(option, default_value) w.config_set_plugin(option, default_value)
def autosave_channels_on_quit(signal, callback, callback_data): def autosave_channels_on_quit(signal, callback, callback_data):
''' Autojoin current channels ''' ''' Autojoin current channels '''
if w.config_get_plugin(option) != "on": if w.config_get_plugin(option) != "on":
@ -121,23 +125,28 @@ def autosave_channels_on_activity(signal, callback, callback_data):
return w.WEECHAT_RC_OK return w.WEECHAT_RC_OK
def autojoin_cb(data, buffer, args):
"""Old behaviour: doesn't save empty channel list"""
"""In fact should also save open buffers with a /part'ed channel"""
"""But I can't believe somebody would want that behaviour"""
items = find_channels()
def autojoin_cb(data, buffer, args):
if args == '--run': if args == '--run':
run = True run = True
elif args != '':
w.prnt('', 'Unexpected argument: %s' % args)
return w.WEECHAT_RC_ERROR
else: else:
run = False run = False
# Old behaviour: doesn't save empty channel list
# In fact should also save open buffers with a /part'ed channel
# But I can't believe somebody would want that behaviour
items = find_channels()
# print/execute commands # print/execute commands
for server, channels in items.items(): for server, channels in items.items():
process_server(server, channels, run) process_server(server, channels, run)
return w.WEECHAT_RC_OK return w.WEECHAT_RC_OK
def process_server(server, channels, run=True): def process_server(server, channels, run=True):
option = "irc.server.%s.autojoin" % server option = "irc.server.%s.autojoin" % server
channels = channels.rstrip(',') channels = channels.rstrip(',')
@ -159,9 +168,10 @@ def process_server(server, channels, run=True):
else: else:
w.prnt('', command) w.prnt('', command)
def find_channels(): def find_channels():
"""Return list of servers and channels""" """Return list of servers and channels"""
#@TODO: make it return a dict with more options like "nicks_count etc." # TODO: make it return a dict with more options like "nicks_count etc."
items = {} items = {}
infolist = w.infolist_get('irc_server', '', '') infolist = w.infolist_get('irc_server', '', '')
# populate servers # populate servers
@ -194,4 +204,3 @@ def find_channels():
w.infolist_free(infolist) w.infolist_free(infolist)
return items return items

View File

@ -31,6 +31,10 @@
# #
# #
# History: # History:
# 2019-08-20
# version 0.3: Ben Harris (benharri)
# * port for python3
#
# 2010-05-08 # 2010-05-08
# version 0.2: # version 0.2:
# * complete any word behind the cursor, not just the last one in input line. # * complete any word behind the cursor, not just the last one in input line.
@ -46,13 +50,13 @@ try:
WEECHAT_RC_OK = weechat.WEECHAT_RC_OK WEECHAT_RC_OK = weechat.WEECHAT_RC_OK
import_ok = True import_ok = True
except ImportError: except ImportError:
print "This script must be run under WeeChat." print("This script must be run under WeeChat.")
print "Get WeeChat now at: http://www.weechat.org/" print("Get WeeChat now at: http://www.weechat.org/")
import_ok = False import_ok = False
SCRIPT_NAME = "completion" SCRIPT_NAME = "completion"
SCRIPT_AUTHOR = "Elián Hanisch <lambdae2@gmail.com>" SCRIPT_AUTHOR = "Elián Hanisch <lambdae2@gmail.com>"
SCRIPT_VERSION = "0.2" SCRIPT_VERSION = "0.3"
SCRIPT_LICENSE = "GPL3" SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Word completions for WeeChat" SCRIPT_DESC = "Word completions for WeeChat"
SCRIPT_COMMAND = "completion" SCRIPT_COMMAND = "completion"
@ -63,16 +67,6 @@ settings = {
} }
### Messages ### ### Messages ###
def decode(s):
if isinstance(s, str):
s = s.decode('utf-8')
return s
def encode(u):
if isinstance(u, unicode):
u = u.encode('utf-8')
return u
def debug(s, prefix='', buffer=None): def debug(s, prefix='', buffer=None):
"""Debug msg""" """Debug msg"""
#if not weechat.config_get_plugin('debug'): return #if not weechat.config_get_plugin('debug'): return
@ -84,13 +78,11 @@ def debug(s, prefix='', buffer=None):
weechat.buffer_set(buffer, 'nicklist', '0') weechat.buffer_set(buffer, 'nicklist', '0')
weechat.buffer_set(buffer, 'time_for_each_line', '0') weechat.buffer_set(buffer, 'time_for_each_line', '0')
weechat.buffer_set(buffer, 'localvar_set_no_log', '1') weechat.buffer_set(buffer, 'localvar_set_no_log', '1')
s = encode(s)
weechat.prnt(buffer, '%s\t%s' %(prefix, s)) weechat.prnt(buffer, '%s\t%s' %(prefix, s))
def error(s, prefix=None, buffer='', trace=''): def error(s, prefix=None, buffer='', trace=''):
"""Error msg""" """Error msg"""
prefix = prefix or script_nick prefix = prefix or script_nick
s = encode(s)
weechat.prnt(buffer, '%s%s %s' %(weechat.prefix('error'), prefix, s)) weechat.prnt(buffer, '%s%s %s' %(weechat.prefix('error'), prefix, s))
if weechat.config_get_plugin('debug'): if weechat.config_get_plugin('debug'):
if not trace: if not trace:
@ -102,67 +94,34 @@ def error(s, prefix=None, buffer='', trace=''):
def say(s, prefix=None, buffer=''): def say(s, prefix=None, buffer=''):
"""normal msg""" """normal msg"""
prefix = prefix or script_nick prefix = prefix or script_nick
s = encode(s)
weechat.prnt(buffer, '%s\t%s' %(prefix, s)) weechat.prnt(buffer, '%s\t%s' %(prefix, s))
print_replace = lambda k,v : say('%s %s=>%s %s' %(k, color_delimiter, color_reset, v)) print_replace = lambda k,v : say('%s %s=>%s %s' %(k, color_delimiter, color_reset, v))
### Config functions ### ### Config functions ###
class UTFDict(dict):
decode = staticmethod(decode)
encode = staticmethod(encode)
def __init__(self, d={}):
dict.__init__(self)
for k, v in d.iteritems():
self[k] = v
def __setitem__(self, k, v):
k = self.decode(k)
v = self.decode(v)
dict.__setitem__(self, k, v)
def __getitem__(self, k):
k = self.decode(k)
return dict.__getitem__(self, k)
def __delitem__(self, k):
k = self.decode(k)
dict.__delitem__(self, k)
def __contains__(self, k):
k = self.decode(k)
return dict.__contains__(self, k)
def __str__(self):
values = [ '%s=>%s' %(k, v) for k, v in self.iteritems() ]
values = ';;'.join(values)
return self.encode(values)
def get_config_dict(config): def get_config_dict(config):
value = weechat.config_get_plugin(config) value = weechat.config_get_plugin(config)
if not value: if not value:
return {} return {}
values = value.split(';;') values = [s.split('=>') for s in value.split(';;')]
values = map(lambda s: s.split('=>'), values)
#debug(values) #debug(values)
return dict(values) return dict(values)
def load_replace_table(): def load_replace_table():
global replace_table global replace_table
replace_table = UTFDict(get_config_dict('replace_values')) replace_table = dict(get_config_dict('replace_values'))
def save_replace_table(): def save_replace_table():
global replace_table global replace_table
weechat.config_set_plugin('replace_values', str(replace_table)) weechat.config_set_plugin('replace_values',
';;'.join(['%s=>%s' %(k, v) for k, v in replace_table.items()]))
### Commands ### ### Commands ###
def cmd_completion(data, buffer, args): def cmd_completion(data, buffer, args):
global replace_table global replace_table
if not args: if not args:
if replace_table: if replace_table:
for k, v in replace_table.iteritems(): for k, v in replace_table.items():
print_replace(k, v) print_replace(k, v)
else: else:
say('No completions.') say('No completions.')
@ -189,7 +148,7 @@ def cmd_completion(data, buffer, args):
def completion_replacer(data, completion_item, buffer, completion): def completion_replacer(data, completion_item, buffer, completion):
global replace_table global replace_table
pos = weechat.buffer_get_integer(buffer, 'input_pos') pos = weechat.buffer_get_integer(buffer, 'input_pos')
input = decode(weechat.buffer_get_string(buffer, 'input')) input = weechat.buffer_get_string(buffer, 'input')
#debug('%r %s %s' %(input, len(input), pos)) #debug('%r %s %s' %(input, len(input), pos))
if pos > 0 and (pos == len(input) or input[pos] == ' '): if pos > 0 and (pos == len(input) or input[pos] == ' '):
n = input.rfind(' ', 0, pos) n = input.rfind(' ', 0, pos)
@ -202,14 +161,14 @@ def completion_replacer(data, completion_item, buffer, completion):
replace += ' ' replace += ' '
n = len(word) n = len(word)
input = '%s%s%s' %(input[:pos-n], replace, input[pos:]) input = '%s%s%s' %(input[:pos-n], replace, input[pos:])
weechat.buffer_set(buffer, 'input', encode(input)) weechat.buffer_set(buffer, 'input', input)
weechat.buffer_set(buffer, 'input_pos', str(pos - n + len(replace))) weechat.buffer_set(buffer, 'input_pos', str(pos - n + len(replace)))
return WEECHAT_RC_OK return WEECHAT_RC_OK
def completion_keys(data, completion_item, buffer, completion): def completion_keys(data, completion_item, buffer, completion):
global replace_table global replace_table
for k in replace_table: for k in replace_table:
weechat.hook_completion_list_add(completion, encode(k), 0, weechat.WEECHAT_LIST_POS_SORT) weechat.hook_completion_list_add(completion, k, 0, weechat.WEECHAT_LIST_POS_SORT)
return WEECHAT_RC_OK return WEECHAT_RC_OK
### Main ### ### Main ###
@ -231,7 +190,7 @@ if __name__ == '__main__' and import_ok and \
error('WeeChat 0.3.1 or newer is required for this script.') error('WeeChat 0.3.1 or newer is required for this script.')
else: else:
# settings # settings
for opt, val in settings.iteritems(): for opt, val in settings.items():
if not weechat.config_is_set_plugin(opt): if not weechat.config_is_set_plugin(opt):
weechat.config_set_plugin(opt, val) weechat.config_set_plugin(opt, val)

View File

@ -21,6 +21,8 @@
# #
# History: # History:
# #
# 2019-07-11, Simmo Saan <simmo.saan@gmail.com>
# version 2.6: fix detection of "/input search_text_here"
# 2017-04-01, Sébastien Helleu <flashcode@flashtux.org>: # 2017-04-01, Sébastien Helleu <flashcode@flashtux.org>:
# version 2.5: add option "buffer_number" # version 2.5: add option "buffer_number"
# 2017-03-02, Sébastien Helleu <flashcode@flashtux.org>: # 2017-03-02, Sébastien Helleu <flashcode@flashtux.org>:
@ -92,7 +94,7 @@ from __future__ import print_function
SCRIPT_NAME = 'go' SCRIPT_NAME = 'go'
SCRIPT_AUTHOR = 'Sébastien Helleu <flashcode@flashtux.org>' SCRIPT_AUTHOR = 'Sébastien Helleu <flashcode@flashtux.org>'
SCRIPT_VERSION = '2.5' SCRIPT_VERSION = '2.6'
SCRIPT_LICENSE = 'GPL3' SCRIPT_LICENSE = 'GPL3'
SCRIPT_DESC = 'Quick jump to buffers' SCRIPT_DESC = 'Quick jump to buffers'
@ -480,7 +482,7 @@ def go_input_modifier(data, modifier, modifier_data, string):
def go_command_run_input(data, buf, command): def go_command_run_input(data, buf, command):
"""Function called when a command "/input xxx" is run.""" """Function called when a command "/input xxx" is run."""
global buffers, buffers_pos global buffers, buffers_pos
if command == '/input search_text' or command.find('/input jump') == 0: if command.startswith('/input search_text') or command.startswith('/input jump'):
# search text or jump to another buffer is forbidden now # search text or jump to another buffer is forbidden now
return weechat.WEECHAT_RC_OK_EAT return weechat.WEECHAT_RC_OK_EAT
elif command == '/input complete_next': elif command == '/input complete_next':

View File

@ -69,6 +69,10 @@
# #
# History: # History:
# #
# 2019-06-30, dabbill <dabbill@gmail.com>
# and Sébastien Helleu <flashcode@flashtux.org>
# version 0.8.2: make script compatible with Python 3
#
# 2018-04-10, Sébastien Helleu <flashcode@flashtux.org> # 2018-04-10, Sébastien Helleu <flashcode@flashtux.org>
# version 0.8.1: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long # version 0.8.1: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long
# integer instead of a string) # integer instead of a string)
@ -226,7 +230,7 @@ except ImportError:
SCRIPT_NAME = "grep" SCRIPT_NAME = "grep"
SCRIPT_AUTHOR = "Elián Hanisch <lambdae2@gmail.com>" SCRIPT_AUTHOR = "Elián Hanisch <lambdae2@gmail.com>"
SCRIPT_VERSION = "0.8.1" SCRIPT_VERSION = "0.8.2"
SCRIPT_LICENSE = "GPL3" SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Search in buffers and logs" SCRIPT_DESC = "Search in buffers and logs"
SCRIPT_COMMAND = "grep" SCRIPT_COMMAND = "grep"
@ -259,14 +263,14 @@ class linesDict(dict):
def get_matches_count(self): def get_matches_count(self):
"""Return the sum of total matches stored.""" """Return the sum of total matches stored."""
if dict.__len__(self): if dict.__len__(self):
return sum(map(lambda L: L.matches_count, self.itervalues())) return sum(map(lambda L: L.matches_count, self.values()))
else: else:
return 0 return 0
def __len__(self): def __len__(self):
"""Return the sum of total lines stored.""" """Return the sum of total lines stored."""
if dict.__len__(self): if dict.__len__(self):
return sum(map(len, self.itervalues())) return sum(map(len, self.values()))
else: else:
return 0 return 0
@ -274,7 +278,7 @@ class linesDict(dict):
"""Returns buffer count or buffer name if there's just one stored.""" """Returns buffer count or buffer name if there's just one stored."""
n = len(self.keys()) n = len(self.keys())
if n == 1: if n == 1:
return self.keys()[0] return list(self.keys())[0]
elif n > 1: elif n > 1:
return '%s logs' %n return '%s logs' %n
else: else:
@ -282,18 +286,18 @@ class linesDict(dict):
def items(self): def items(self):
"""Returns a list of items sorted by line count.""" """Returns a list of items sorted by line count."""
items = dict.items(self) items = list(dict.items(self))
items.sort(key=lambda i: len(i[1])) items.sort(key=lambda i: len(i[1]))
return items return items
def items_count(self): def items_count(self):
"""Returns a list of items sorted by match count.""" """Returns a list of items sorted by match count."""
items = dict.items(self) items = list(dict.items(self))
items.sort(key=lambda i: i[1].matches_count) items.sort(key=lambda i: i[1].matches_count)
return items return items
def strip_separator(self): def strip_separator(self):
for L in self.itervalues(): for L in self.values():
L.strip_separator() L.strip_separator()
def get_last_lines(self, n): def get_last_lines(self, n):
@ -302,7 +306,7 @@ class linesDict(dict):
if n >= total_lines: if n >= total_lines:
# nothing to do # nothing to do
return return
for k, v in reversed(self.items()): for k, v in reversed(list(self.items())):
l = len(v) l = len(v)
if n > 0: if n > 0:
if l > n: if l > n:
@ -657,8 +661,8 @@ def make_regexp(pattern, matchcase=False):
regexp = re.compile(pattern, re.IGNORECASE) regexp = re.compile(pattern, re.IGNORECASE)
else: else:
regexp = re.compile(pattern) regexp = re.compile(pattern)
except Exception, e: except Exception as e:
raise Exception, 'Bad pattern, %s' %e raise Exception('Bad pattern, %s' % e)
return regexp return regexp
def check_string(s, regexp, hilight='', exact=False): def check_string(s, regexp, hilight='', exact=False):
@ -736,7 +740,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi
before_context, after_context = after_context, before_context before_context, after_context = after_context, before_context
if before_context: if before_context:
before_context_range = range(1, before_context + 1) before_context_range = list(range(1, before_context + 1))
before_context_range.reverse() before_context_range.reverse()
limit = tail or head limit = tail or head
@ -800,7 +804,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi
while id < after_context + offset: while id < after_context + offset:
id += 1 id += 1
try: try:
context_line = file_object.next() context_line = next(file_object)
_context_line = check(context_line) _context_line = check(context_line)
if _context_line: if _context_line:
offset = id offset = id
@ -1002,7 +1006,7 @@ def grep_process(*args):
global grep_options, log_pairs global grep_options, log_pairs
for log_name, log in log_pairs: for log_name, log in log_pairs:
result[log_name] = grep_file(log, *grep_options) result[log_name] = grep_file(log, *grep_options)
except Exception, e: except Exception as e:
result = e result = e
return pickle.dumps(result) return pickle.dumps(result)
@ -1038,7 +1042,7 @@ def grep_process_cb(data, command, return_code, out, err):
if isinstance(data, Exception): if isinstance(data, Exception):
raise data raise data
matched_lines.update(data) matched_lines.update(data)
except Exception, e: except Exception as e:
set_buffer_error(repr(e)) set_buffer_error(repr(e))
return WEECHAT_RC_OK return WEECHAT_RC_OK
else: else:
@ -1280,12 +1284,12 @@ def buffer_input(data, buffer, input_data):
weechat.infolist_free(infolist) weechat.infolist_free(infolist)
try: try:
cmd_grep_parsing(input_data) cmd_grep_parsing(input_data)
except Exception, e: except Exception as e:
error('Argument error, %s' % e, buffer=buffer) error('Argument error, %s' % e, buffer=buffer)
return WEECHAT_RC_OK return WEECHAT_RC_OK
try: try:
show_matching_lines() show_matching_lines()
except Exception, e: except Exception as e:
error(e) error(e)
except NameError: except NameError:
error("There isn't any previous search to repeat.", buffer=buffer) error("There isn't any previous search to repeat.", buffer=buffer)
@ -1346,7 +1350,7 @@ def cmd_grep_parsing(args):
pattern = _tmplRe.sub(tmplReplacer, args) pattern = _tmplRe.sub(tmplReplacer, args)
debug('Using regexp: %s', pattern) debug('Using regexp: %s', pattern)
if not pattern: if not pattern:
raise Exception, 'No pattern for grep the logs.' raise Exception('No pattern for grep the logs.')
def positive_number(opt, val): def positive_number(opt, val):
try: try:
@ -1359,7 +1363,7 @@ def cmd_grep_parsing(args):
opt = '-' + opt opt = '-' + opt
else: else:
opt = '--' + opt opt = '--' + opt
raise Exception, "argument for %s must be a positive integer." %opt raise Exception("argument for %s must be a positive integer." % opt)
for opt, val in opts: for opt, val in opts:
opt = opt.strip('-') opt = opt.strip('-')
@ -1454,7 +1458,7 @@ def cmd_grep(data, buffer, args):
# parse # parse
try: try:
cmd_grep_parsing(args) cmd_grep_parsing(args)
except Exception, e: except Exception as e:
error('Argument error, %s' % e) error('Argument error, %s' % e)
return WEECHAT_RC_OK return WEECHAT_RC_OK
@ -1501,7 +1505,7 @@ def cmd_grep(data, buffer, args):
# grepping # grepping
try: try:
show_matching_lines() show_matching_lines()
except Exception, e: except Exception as e:
error(e) error(e)
return WEECHAT_RC_OK return WEECHAT_RC_OK
@ -1520,7 +1524,7 @@ def cmd_logs(data, buffer, args):
opt = opt.strip('-') opt = opt.strip('-')
if opt in ('size', 's'): if opt in ('size', 's'):
sort_by_size = True sort_by_size = True
except Exception, e: except Exception as e:
error('Argument error, %s' % e) error('Argument error, %s' % e)
return WEECHAT_RC_OK return WEECHAT_RC_OK
@ -1703,7 +1707,7 @@ Examples:
'completion_grep_args', '') 'completion_grep_args', '')
# settings # settings
for opt, val in settings.iteritems(): for opt, val in settings.items():
if not weechat.config_is_set_plugin(opt): if not weechat.config_is_set_plugin(opt):
weechat.config_set_plugin(opt, val) weechat.config_set_plugin(opt, val)

View File

@ -354,9 +354,11 @@ default.current = on
[notify] [notify]
irc.bitlbee = highlight irc.bitlbee = highlight
perl.highmon = none
[filter] [filter]
irc_smart = on;*;irc_smart_filter;* irc_smart = on;*;irc_smart_filter;*
markov_bitbot = on;irc.tilde.*;irc_privmsg;^,m(\s|arkov)|^\[Markov\]
[key] [key]
ctrl-? = "/input delete_previous_char" ctrl-? = "/input delete_previous_char"