mirror of https://tildegit.org/ben/dotfiles
upgrade scripts
parent
1a50c40f82
commit
0961632f01
|
@ -69,6 +69,7 @@ python.grep.log_filter = ""
|
||||||
python.grep.max_lines = "4000"
|
python.grep.max_lines = "4000"
|
||||||
python.grep.show_summary = "on"
|
python.grep.show_summary = "on"
|
||||||
python.grep.size_limit = "2048"
|
python.grep.size_limit = "2048"
|
||||||
|
python.grep.timeout_secs = "300"
|
||||||
python.screen_away.away_suffix = ""
|
python.screen_away.away_suffix = ""
|
||||||
python.screen_away.command_on_attach = ""
|
python.screen_away.command_on_attach = ""
|
||||||
python.screen_away.command_on_detach = ""
|
python.screen_away.command_on_detach = ""
|
||||||
|
@ -78,6 +79,8 @@ python.screen_away.interval = "5"
|
||||||
python.screen_away.message = "Detached from screen"
|
python.screen_away.message = "Detached from screen"
|
||||||
python.screen_away.set_away = "on"
|
python.screen_away.set_away = "on"
|
||||||
python.screen_away.time_format = "since %Y-%m-%d %H:%M:%S%z"
|
python.screen_away.time_format = "since %Y-%m-%d %H:%M:%S%z"
|
||||||
|
python.topicdiff_alt.color_del = "darkgray"
|
||||||
|
python.topicdiff_alt.color_ins = "lightcyan"
|
||||||
ruby.check_license = "off"
|
ruby.check_license = "off"
|
||||||
tcl.check_license = "off"
|
tcl.check_license = "off"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
../topicdiff_alt.py
|
|
@ -53,6 +53,9 @@
|
||||||
# It can be used for force or disable background process, using '0' forces to always grep in
|
# It can be used for force or disable background process, using '0' forces to always grep in
|
||||||
# background, while using '' (empty string) will disable it.
|
# background, while using '' (empty string) will disable it.
|
||||||
#
|
#
|
||||||
|
# * plugins.var.python.grep.timeout_secs:
|
||||||
|
# Timeout (in seconds) for background grepping.
|
||||||
|
#
|
||||||
# * plugins.var.python.grep.default_tail_head:
|
# * plugins.var.python.grep.default_tail_head:
|
||||||
# Config option for define default number of lines returned when using --head or --tail options.
|
# Config option for define default number of lines returned when using --head or --tail options.
|
||||||
# Can be overriden in the command with --number option.
|
# Can be overriden in the command with --number option.
|
||||||
|
@ -66,6 +69,24 @@
|
||||||
#
|
#
|
||||||
# History:
|
# History:
|
||||||
#
|
#
|
||||||
|
# 2018-04-10, Sébastien Helleu <flashcode@flashtux.org>
|
||||||
|
# version 0.8.1: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long
|
||||||
|
# integer instead of a string)
|
||||||
|
#
|
||||||
|
# 2017-09-20, mickael9
|
||||||
|
# version 0.8:
|
||||||
|
# * use weechat 1.5+ api for background processing (old method was unsafe and buggy)
|
||||||
|
# * add timeout_secs setting (was previously hardcoded to 5 mins)
|
||||||
|
#
|
||||||
|
# 2017-07-23, Sébastien Helleu <flashcode@flashtux.org>
|
||||||
|
# version 0.7.8: fix modulo by zero when nick is empty string
|
||||||
|
#
|
||||||
|
# 2016-06-23, mickael9
|
||||||
|
# version 0.7.7: fix get_home function
|
||||||
|
#
|
||||||
|
# 2015-11-26
|
||||||
|
# version 0.7.6: fix a typo
|
||||||
|
#
|
||||||
# 2015-01-31, Nicd-
|
# 2015-01-31, Nicd-
|
||||||
# version 0.7.5:
|
# version 0.7.5:
|
||||||
# '~' is now expaned to the home directory in the log file path so
|
# '~' is now expaned to the home directory in the log file path so
|
||||||
|
@ -189,7 +210,12 @@
|
||||||
###
|
###
|
||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
import sys, getopt, time, os, re, tempfile
|
import sys, getopt, time, os, re
|
||||||
|
|
||||||
|
try:
|
||||||
|
import cPickle as pickle
|
||||||
|
except ImportError:
|
||||||
|
import pickle
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import weechat
|
import weechat
|
||||||
|
@ -200,7 +226,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.7.5"
|
SCRIPT_VERSION = "0.8.1"
|
||||||
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"
|
||||||
|
@ -214,6 +240,7 @@ settings = {
|
||||||
'show_summary' : 'on',
|
'show_summary' : 'on',
|
||||||
'size_limit' : '2048',
|
'size_limit' : '2048',
|
||||||
'default_tail_head' : '10',
|
'default_tail_head' : '10',
|
||||||
|
'timeout_secs' : '300',
|
||||||
}
|
}
|
||||||
|
|
||||||
### Class definitions ###
|
### Class definitions ###
|
||||||
|
@ -372,6 +399,8 @@ def color_nick(nick):
|
||||||
else:
|
else:
|
||||||
mode = mode_color = ''
|
mode = mode_color = ''
|
||||||
# nick color
|
# nick color
|
||||||
|
nick_color = ''
|
||||||
|
if nick:
|
||||||
nick_color = weechat.info_get('irc_nick_color', nick)
|
nick_color = weechat.info_get('irc_nick_color', nick)
|
||||||
if not nick_color:
|
if not nick_color:
|
||||||
# probably we're in WeeChat 0.3.0
|
# probably we're in WeeChat 0.3.0
|
||||||
|
@ -414,8 +443,9 @@ def get_config_log_filter():
|
||||||
|
|
||||||
def get_home():
|
def get_home():
|
||||||
home = weechat.config_string(weechat.config_get('logger.file.path'))
|
home = weechat.config_string(weechat.config_get('logger.file.path'))
|
||||||
|
home = home.replace('%h', weechat.info_get('weechat_dir', ''))
|
||||||
home = path.abspath(path.expanduser(home))
|
home = path.abspath(path.expanduser(home))
|
||||||
return home.replace('%h', weechat.info_get('weechat_dir', ''))
|
return home
|
||||||
|
|
||||||
def strip_home(s, dir=''):
|
def strip_home(s, dir=''):
|
||||||
"""Strips home dir from the begging of the log path, this makes them sorter."""
|
"""Strips home dir from the begging of the log path, this makes them sorter."""
|
||||||
|
@ -818,6 +848,10 @@ def grep_buffer(buffer, head, tail, after_context, before_context, count, regexp
|
||||||
prefix = string_remove_color(infolist_string(infolist, 'prefix'), '')
|
prefix = string_remove_color(infolist_string(infolist, 'prefix'), '')
|
||||||
message = string_remove_color(infolist_string(infolist, 'message'), '')
|
message = string_remove_color(infolist_string(infolist, 'message'), '')
|
||||||
date = infolist_time(infolist, 'date')
|
date = infolist_time(infolist, 'date')
|
||||||
|
# since WeeChat 2.2, infolist_time returns a long integer
|
||||||
|
# instead of a string
|
||||||
|
if not isinstance(date, str):
|
||||||
|
date = time.strftime('%F %T', time.localtime(int(date)))
|
||||||
return '%s\t%s\t%s' %(date, prefix, message)
|
return '%s\t%s\t%s' %(date, prefix, message)
|
||||||
return function
|
return function
|
||||||
get_line = make_get_line_funcion()
|
get_line = make_get_line_funcion()
|
||||||
|
@ -931,104 +965,85 @@ def show_matching_lines():
|
||||||
elif size_limit == '':
|
elif size_limit == '':
|
||||||
background = False
|
background = False
|
||||||
|
|
||||||
|
regexp = make_regexp(pattern, matchcase)
|
||||||
|
|
||||||
|
global grep_options, log_pairs
|
||||||
|
grep_options = (head, tail, after_context, before_context,
|
||||||
|
count, regexp, hilight, exact, invert)
|
||||||
|
|
||||||
|
log_pairs = [(strip_home(log), log) for log in search_in_files]
|
||||||
|
|
||||||
if not background:
|
if not background:
|
||||||
# run grep normally
|
# run grep normally
|
||||||
regexp = make_regexp(pattern, matchcase)
|
for log_name, log in log_pairs:
|
||||||
for log in search_in_files:
|
matched_lines[log_name] = grep_file(log, *grep_options)
|
||||||
log_name = strip_home(log)
|
|
||||||
matched_lines[log_name] = grep_file(log, head, tail, after_context, before_context,
|
|
||||||
count, regexp, hilight, exact, invert)
|
|
||||||
buffer_update()
|
buffer_update()
|
||||||
else:
|
else:
|
||||||
# we hook a process so grepping runs in background.
|
global hook_file_grep, grep_stdout, grep_stderr, pattern_tmpl
|
||||||
#debug('on background')
|
grep_stdout = grep_stderr = ''
|
||||||
global hook_file_grep, script_path, bytecode
|
hook_file_grep = weechat.hook_process(
|
||||||
timeout = 1000*60*5 # 5 min
|
'func:grep_process',
|
||||||
|
get_config_int('timeout_secs') * 1000,
|
||||||
quotify = lambda s: '"%s"' %s
|
'grep_process_cb',
|
||||||
files_string = ', '.join(map(quotify, search_in_files))
|
''
|
||||||
|
)
|
||||||
global tmpFile
|
|
||||||
# we keep the file descriptor as a global var so it isn't deleted until next grep
|
|
||||||
tmpFile = tempfile.NamedTemporaryFile(prefix=SCRIPT_NAME,
|
|
||||||
dir=weechat.info_get('weechat_dir', ''))
|
|
||||||
cmd = grep_process_cmd %dict(logs=files_string, head=head, pattern=pattern, tail=tail,
|
|
||||||
hilight=hilight, after_context=after_context, before_context=before_context,
|
|
||||||
exact=exact, matchcase=matchcase, home_dir=home_dir, script_path=script_path,
|
|
||||||
count=count, invert=invert, bytecode=bytecode, filename=tmpFile.name,
|
|
||||||
python=weechat.info_get('python2_bin', '') or 'python')
|
|
||||||
|
|
||||||
#debug(cmd)
|
|
||||||
hook_file_grep = weechat.hook_process(cmd, timeout, 'grep_file_callback', tmpFile.name)
|
|
||||||
global pattern_tmpl
|
|
||||||
if hook_file_grep:
|
if hook_file_grep:
|
||||||
buffer_create("Searching for '%s' in %s worth of data..." %(pattern_tmpl,
|
buffer_create("Searching for '%s' in %s worth of data..." % (
|
||||||
human_readable_size(size)))
|
pattern_tmpl,
|
||||||
|
human_readable_size(size)
|
||||||
|
))
|
||||||
else:
|
else:
|
||||||
buffer_update()
|
buffer_update()
|
||||||
|
|
||||||
# defined here for commodity
|
|
||||||
grep_process_cmd = """%(python)s -%(bytecode)sc '
|
def grep_process(*args):
|
||||||
import sys, cPickle, os
|
result = {}
|
||||||
sys.path.append("%(script_path)s") # add WeeChat script dir so we can import grep
|
|
||||||
from grep import make_regexp, grep_file, strip_home
|
|
||||||
logs = (%(logs)s, )
|
|
||||||
try:
|
try:
|
||||||
regexp = make_regexp("%(pattern)s", %(matchcase)s)
|
global grep_options, log_pairs
|
||||||
d = {}
|
for log_name, log in log_pairs:
|
||||||
for log in logs:
|
result[log_name] = grep_file(log, *grep_options)
|
||||||
log_name = strip_home(log, "%(home_dir)s")
|
|
||||||
lines = grep_file(log, %(head)s, %(tail)s, %(after_context)s, %(before_context)s,
|
|
||||||
%(count)s, regexp, "%(hilight)s", %(exact)s, %(invert)s)
|
|
||||||
d[log_name] = lines
|
|
||||||
fd = open("%(filename)s", "wb")
|
|
||||||
cPickle.dump(d, fd, -1)
|
|
||||||
fd.close()
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print >> sys.stderr, e'
|
result = e
|
||||||
"""
|
|
||||||
|
return pickle.dumps(result)
|
||||||
|
|
||||||
grep_stdout = grep_stderr = ''
|
grep_stdout = grep_stderr = ''
|
||||||
def grep_file_callback(filename, command, rc, stdout, stderr):
|
|
||||||
global hook_file_grep, grep_stderr, grep_stdout
|
|
||||||
global matched_lines
|
|
||||||
#debug("rc: %s\nstderr: %s\nstdout: %s" %(rc, repr(stderr), repr(stdout)))
|
|
||||||
if stdout:
|
|
||||||
grep_stdout += stdout
|
|
||||||
if stderr:
|
|
||||||
grep_stderr += stderr
|
|
||||||
if int(rc) >= 0:
|
|
||||||
|
|
||||||
def set_buffer_error():
|
def grep_process_cb(data, command, return_code, out, err):
|
||||||
|
global grep_stdout, grep_stderr, matched_lines, hook_file_grep
|
||||||
|
|
||||||
|
grep_stdout += out
|
||||||
|
grep_stderr += err
|
||||||
|
|
||||||
|
def set_buffer_error(message):
|
||||||
|
error(message)
|
||||||
grep_buffer = buffer_create()
|
grep_buffer = buffer_create()
|
||||||
title = weechat.buffer_get_string(grep_buffer, 'title')
|
title = weechat.buffer_get_string(grep_buffer, 'title')
|
||||||
title = title + ' %serror' % color_title
|
title = title + ' %serror' % color_title
|
||||||
weechat.buffer_set(grep_buffer, 'title', title)
|
weechat.buffer_set(grep_buffer, 'title', title)
|
||||||
|
|
||||||
try:
|
if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR:
|
||||||
|
set_buffer_error("Background grep timed out")
|
||||||
|
hook_file_grep = None
|
||||||
|
return WEECHAT_RC_OK
|
||||||
|
|
||||||
|
elif return_code >= 0:
|
||||||
|
hook_file_grep = None
|
||||||
if grep_stderr:
|
if grep_stderr:
|
||||||
error(grep_stderr)
|
set_buffer_error(grep_stderr)
|
||||||
set_buffer_error()
|
return WEECHAT_RC_OK
|
||||||
#elif grep_stdout:
|
|
||||||
#debug(grep_stdout)
|
|
||||||
elif path.exists(filename):
|
|
||||||
import cPickle
|
|
||||||
try:
|
try:
|
||||||
#debug(file)
|
data = pickle.loads(grep_stdout)
|
||||||
fd = open(filename, 'rb')
|
if isinstance(data, Exception):
|
||||||
d = cPickle.load(fd)
|
raise data
|
||||||
matched_lines.update(d)
|
matched_lines.update(data)
|
||||||
fd.close()
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
error(e)
|
set_buffer_error(repr(e))
|
||||||
set_buffer_error()
|
return WEECHAT_RC_OK
|
||||||
else:
|
else:
|
||||||
buffer_update()
|
buffer_update()
|
||||||
global tmpFile
|
|
||||||
tmpFile = None
|
|
||||||
finally:
|
|
||||||
grep_stdout = grep_stderr = ''
|
|
||||||
hook_file_grep = None
|
|
||||||
return WEECHAT_RC_OK
|
return WEECHAT_RC_OK
|
||||||
|
|
||||||
def get_grep_file_status():
|
def get_grep_file_status():
|
||||||
|
@ -1403,18 +1418,18 @@ def cmd_grep_parsing(args):
|
||||||
tail = n
|
tail = n
|
||||||
|
|
||||||
def cmd_grep_stop(buffer, args):
|
def cmd_grep_stop(buffer, args):
|
||||||
global hook_file_grep, pattern, matched_lines, tmpFile
|
global hook_file_grep, pattern, matched_lines
|
||||||
if hook_file_grep:
|
if hook_file_grep:
|
||||||
if args == 'stop':
|
if args == 'stop':
|
||||||
weechat.unhook(hook_file_grep)
|
weechat.unhook(hook_file_grep)
|
||||||
hook_file_grep = None
|
hook_file_grep = None
|
||||||
|
|
||||||
s = 'Search for \'%s\' stopped.' % pattern
|
s = 'Search for \'%s\' stopped.' % pattern
|
||||||
say(s, buffer)
|
say(s, buffer)
|
||||||
grep_buffer = weechat.buffer_search('python', SCRIPT_NAME)
|
grep_buffer = weechat.buffer_search('python', SCRIPT_NAME)
|
||||||
if grep_buffer:
|
if grep_buffer:
|
||||||
weechat.buffer_set(grep_buffer, 'title', s)
|
weechat.buffer_set(grep_buffer, 'title', s)
|
||||||
del matched_lines
|
matched_lines = {}
|
||||||
tmpFile = None
|
|
||||||
else:
|
else:
|
||||||
say(get_grep_file_status(), buffer)
|
say(get_grep_file_status(), buffer)
|
||||||
raise Exception
|
raise Exception
|
||||||
|
@ -1639,7 +1654,7 @@ if __name__ == '__main__' and import_ok and \
|
||||||
If used with 'log <file>' search in all logs that matches <file>.
|
If used with 'log <file>' search in all logs that matches <file>.
|
||||||
-b --buffer: Search only in buffers, not in file logs.
|
-b --buffer: Search only in buffers, not in file logs.
|
||||||
-c --count: Just count the number of matched lines instead of showing them.
|
-c --count: Just count the number of matched lines instead of showing them.
|
||||||
-m --matchcase: Don't do case insensible search.
|
-m --matchcase: Don't do case insensitive search.
|
||||||
-H --hilight: Colour exact matches in output buffer.
|
-H --hilight: Colour exact matches in output buffer.
|
||||||
-o --only-match: Print only the matching part of the line (unique matches).
|
-o --only-match: Print only the matching part of the line (unique matches).
|
||||||
-v -i --invert: Print lines that don't match the regular expression.
|
-v -i --invert: Print lines that don't match the regular expression.
|
||||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,70 @@
|
||||||
|
import weechat
|
||||||
|
import diff_match_patch
|
||||||
|
import re
|
||||||
|
|
||||||
|
weechat.register('topicdiff_alt', 'Juerd <#####@juerd.nl>', '1.01', 'PD', "Announce topic with changes highlighted", '', '')
|
||||||
|
|
||||||
|
def topic(data, tags, msg):
|
||||||
|
server = tags.split(",")[0]
|
||||||
|
|
||||||
|
match = re.search(r':(\S+)\s+TOPIC\s+(\S+)\s+:(.*)', msg)
|
||||||
|
|
||||||
|
if not match:
|
||||||
|
return weechat.WEECHAT_RC_ERROR
|
||||||
|
|
||||||
|
usermask, channel, newtopic = match.groups()
|
||||||
|
nick, host = usermask.split("!", 1)
|
||||||
|
|
||||||
|
buffer = weechat.buffer_search("irc", server + "." + channel)
|
||||||
|
weechat.prnt("", server + "." + channel)
|
||||||
|
|
||||||
|
if not buffer:
|
||||||
|
return weechat.WEECHAT_RC_ERROR
|
||||||
|
|
||||||
|
oldtopic = weechat.buffer_get_string(buffer, "title")
|
||||||
|
if oldtopic == None:
|
||||||
|
oldtopic = ""
|
||||||
|
|
||||||
|
dmp = diff_match_patch.diff_match_patch()
|
||||||
|
diff = dmp.diff_main(oldtopic, newtopic)
|
||||||
|
dmp.diff_cleanupEfficiency(diff)
|
||||||
|
|
||||||
|
topic = ""
|
||||||
|
|
||||||
|
color_reset = weechat.color("reset")
|
||||||
|
color_ins = weechat.color(weechat.config_get_plugin("color_ins"))
|
||||||
|
color_del = weechat.color(weechat.config_get_plugin("color_del"))
|
||||||
|
|
||||||
|
for chunk in diff:
|
||||||
|
changed, text = chunk
|
||||||
|
|
||||||
|
topic += "%s%s%s" % (
|
||||||
|
# 0 (unchanged), 1 (added), -1 (removed)
|
||||||
|
["", color_ins, color_del][changed],
|
||||||
|
text,
|
||||||
|
["", color_reset, color_reset][changed]
|
||||||
|
)
|
||||||
|
|
||||||
|
weechat.prnt_date_tags(buffer, 0, "irc_topicdiff",
|
||||||
|
"%s%s%s%s has changed topic for %s%s%s: %s" % (
|
||||||
|
weechat.prefix("network"),
|
||||||
|
weechat.color(weechat.info_get("irc_nick_color", nick)) \
|
||||||
|
if weechat.config_boolean("irc.look.color_nicks_in_server_messages") \
|
||||||
|
else weechat.color("chat_nick"),
|
||||||
|
nick,
|
||||||
|
color_reset,
|
||||||
|
weechat.color("chat_channel"),
|
||||||
|
channel,
|
||||||
|
color_reset,
|
||||||
|
topic
|
||||||
|
))
|
||||||
|
|
||||||
|
return weechat.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
weechat.hook_signal("*,irc_in_topic", "topic", "")
|
||||||
|
|
||||||
|
if not weechat.config_is_set_plugin("color_ins"):
|
||||||
|
weechat.config_set_plugin("color_ins", "lightcyan")
|
||||||
|
|
||||||
|
if not weechat.config_is_set_plugin("color_del"):
|
||||||
|
weechat.config_set_plugin("color_del", "darkgray")
|
|
@ -360,6 +360,7 @@ irc.tilde = message
|
||||||
irc.town = message
|
irc.town = message
|
||||||
|
|
||||||
[filter]
|
[filter]
|
||||||
|
irc_smart = on;irc.freenode.#git;irc_smart_filter;*
|
||||||
|
|
||||||
[key]
|
[key]
|
||||||
ctrl-? = "/input delete_previous_char"
|
ctrl-? = "/input delete_previous_char"
|
||||||
|
|
Loading…
Reference in New Issue