#
# highmon.pl - Highlight Monitoring for weechat 0.3.0
-# Version 2.5
+# Version 2.6
#
# Add 'Highlight Monitor' buffer/bar to log all highlights in one spot
#
# Bugs and feature requests at: https://github.com/KenjiE20/highmon
# History:
+# 2019-05-13, HubbeKing <hubbe128@gmail.com>
+# v2.6: -add: send "logger_backlog" signal on buffer open if logging is enabled
# 2014-08-16, KenjiE20 <longbow@longbowslair.co.uk>:
# v2.5: -add: clearbar command to clear bar output
# -add: firstrun output prompt to check the help text for set up hints as they were being missed
# Turn off notify, highlights
if ($highmon_buffer ne "")
{
- if (weechat::config_get_plugin("hotlist_show" eq "off"))
+ if (weechat::config_get_plugin("hotlist_show") eq "off")
{
weechat::buffer_set($highmon_buffer, "notify", "0");
}
{
weechat::buffer_set($highmon_buffer, "localvar_set_no_log", "1");
}
+ # send "logger_backlog" signal if logging is enabled to display backlog
+ if (weechat::config_get_plugin("logging") eq "on")
+ {
+ weechat::hook_signal_send("logger_backlog", weechat::WEECHAT_HOOK_SIGNAL_POINTER, $highmon_buffer)
+ }
}
return weechat::WEECHAT_RC_OK;
}
}
# Check result of register, and attempt to behave in a sane manner
-if (!weechat::register("highmon", "KenjiE20", "2.5", "GPL3", "Highlight Monitor", "", ""))
+if (!weechat::register("highmon", "KenjiE20", "2.6", "GPL3", "Highlight Monitor", "", ""))
{
# Double load
weechat::print ("", "\tHighmon is already loaded");
#
# Changelog:
+# 3.6:
+# * Add more documentation on provided info hooks.
+# 3.5:
+# * Add ${info:autosort_escape,...} to escape arguments for other info hooks.
# 3.4:
# * Fix rate-limit of sorting to prevent high CPU load and lock-ups.
# * Fix bug in parsing empty arguments for info hooks.
SCRIPT_NAME = 'autosort'
SCRIPT_AUTHOR = 'Maarten de Vries <maarten@de-vri.es>'
-SCRIPT_VERSION = '3.4'
+SCRIPT_VERSION = '3.6'
SCRIPT_LICENSE = 'GPL3'
SCRIPT_DESC = 'Flexible automatic (or manual) buffer sorting based on eval expressions.'
'irc_last': '${if:${buffer.plugin.name}==irc}',
'irc_raw_first': '${if:${buffer.full_name}!=irc.irc_raw}',
'irc_raw_last': '${if:${buffer.full_name}==irc.irc_raw}',
- 'hashless_name': '${info:autosort_replace,#,,${buffer.name}}',
+ 'hashless_name': '${info:autosort_replace,#,,${info:autosort_escape,${buffer.name}}}',
})
default_signal_delay = 5
if args is None: break
return result, args
+def on_info_escape(pointer, name, arguments):
+ result = ''
+ for c in arguments:
+ if c == '\\':
+ result += '\\\\'
+ elif c == ',':
+ result += '\\,'
+ else:
+ result +=c
+ return result
+
def on_info_replace(pointer, name, arguments):
arguments, rest = parse_args(arguments, 3)
if rest or len(arguments) < 3:
Swap the expressions of two helper variables in the list.
+{*white}# Info hooks{reset}
+Autosort comes with a number of info hooks to add some extra functionality to regular weechat eval strings.
+Info hooks can be used in eval strings in the form of {cyan}${{info:some_hook,arguments}}{reset}.
+
+Commas and backslashes in arguments to autosort info hooks (except for {cyan}${{info:autosort_escape}}{reset}) must be escaped with a backslash.
+
+{*white}${{info:{brown}autosort_replace{white},{cyan}pattern{white},{cyan}replacement{white},{cyan}source{white}}}{reset}
+Replace all occurrences of {cyan}pattern{reset} with {cyan}replacement{reset} in the string {cyan}source{reset}.
+Can be used to ignore certain strings when sorting by replacing them with an empty string.
+
+For example: {cyan}${{info:autosort_replace,cat,dog,the dog is meowing}}{reset} expands to "the cat is meowing".
+
+{*white}${{info:{brown}autosort_order{white},{cyan}value{white},{cyan}option0{white},{cyan}option1{white},{cyan}option2{white},{cyan}...{white}}}
+Generate a zero-padded number that corresponds to the index of {cyan}value{reset} in the list of options.
+If one of the options is the special value {brown}*{reset}, then any value not explicitly mentioned will be sorted at that position.
+Otherwise, any value that does not match an option is assigned the highest number available.
+Can be used to easily sort buffers based on a manual sequence.
+
+For example: {cyan}${{info:autosort_order,${{server}},freenode,oftc,efnet}}{reset} will sort freenode before oftc, followed by efnet and then any remaining servers.
+Alternatively, {cyan}${{info:autosort_order,${{server}},freenode,oftc,*,efnet}}{reset} will sort any unlisted servers after freenode and oftc, but before efnet.
+
+{*white}${{info:{brown}autosort_escape{white},{cyan}text{white}}}{reset}
+Escape commas and backslashes in {cyan}text{reset} by prepending them with a backslash.
+This is mainly useful to pass arbitrary eval strings as arguments to other autosort info hooks.
+Otherwise, an eval string that expands to something with a comma would be interpreted as multiple arguments.
+
+For example, it can be used to safely pass buffer names to {cyan}${{info:autosort_replace}}{reset} like so:
+{cyan}${{info:autosort_replace,##,#,${{info:autosort_escape,${{buffer.name}}}}}}{reset}.
+
+
{*white}# Description
Autosort is a weechat script to automatically keep your buffers sorted. The sort
order can be customized by defining your own sort rules, but the default should
a helper variable named `{cyan}foo{reset}` can be accessed in a main rule with the
string `{cyan}${{foo}}{reset}`.
-{*white}# Replacing substrings{reset}
-There is no default method for replacing text inside eval expressions. However,
-autosort adds a `replace` info hook that can be used inside eval expressions:
- {cyan}${{info:autosort_replace,from,to,text}}{reset}
-
-For example, to strip all hashes from a buffer name, you could write:
- {cyan}${{info:autosort_replace,#,,${{buffer.name}}}}{reset}
-
-You can escape commas and backslashes inside the arguments by prefixing them with
-a backslash.
-
{*white}# Automatic or manual sorting{reset}
By default, autosort will automatically sort your buffer list whenever a buffer
is opened, merged, unmerged or renamed. This should keep your buffers sorted in
command_completion = '%(plugin_autosort) %(plugin_autosort) %(plugin_autosort) %(plugin_autosort) %(plugin_autosort)'
-info_replace_description = 'Replace all occurences of `from` with `to` in the string `text`.'
-info_replace_arguments = 'from,to,text'
+info_replace_description = (
+ 'Replace all occurrences of `pattern` with `replacement` in the string `source`. '
+ 'Can be used to ignore certain strings when sorting by replacing them with an empty string. '
+ 'See /help autosort for examples.'
+)
+info_replace_arguments = 'pattern,replacement,source'
info_order_description = (
- 'Get a zero padded index of a value in a list of possible values.'
- 'If the value is not found, the index for `*` is returned.'
- 'If there is no `*` in the list, the highest index + 1 is returned.'
+ 'Generate a zero-padded number that corresponds to the index of `value` in the list of options. '
+ 'If one of the options is the special value `*`, then any value not explicitly mentioned will be sorted at that position. '
+ 'Otherwise, any value that does not match an option is assigned the highest number available. '
+ 'Can be used to easily sort buffers based on a manual sequence. '
+ 'See /help autosort for examples.'
+)
+info_order_arguments = 'value,first,second,third,...'
+
+info_escape_description = (
+ 'Escape commas and backslashes in `text` by prepending them with a backslash. '
+ 'This is mainly useful to pass arbitrary eval strings as arguments to other autosort info hooks. '
+ 'Otherwise, an eval string that expands to something with a comma would be interpreted as multiple arguments.'
+ 'See /help autosort for examples.'
)
-info_order_arguments = 'value,first,second,third,...'
+info_escape_arguments = 'text'
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
weechat.hook_config('autosort.*', 'on_config_changed', '')
weechat.hook_completion('plugin_autosort', '', 'on_autosort_complete', '')
weechat.hook_command('autosort', command_description.format(**colors), '', '', command_completion, 'on_autosort_command', '')
+ weechat.hook_info('autosort_escape', info_escape_description, info_escape_arguments, 'on_info_escape', '')
weechat.hook_info('autosort_replace', info_replace_description, info_replace_arguments, 'on_info_replace', '')
weechat.hook_info('autosort_order', info_order_description, info_order_arguments, 'on_info_order', '')
#
# 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>
# version 0.8.1: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long
# integer instead of a string)
# * supress highlights when printing in grep buffer
#
# 2010-10-06
-# version 0.6.7: by xt <xt@bash.no>
+# version 0.6.7: by xt <xt@bash.no>
# * better temporary file:
-# use tempfile.mkstemp. to create a temp file in log dir,
+# use tempfile.mkstemp. to create a temp file in log dir,
# makes it safer with regards to write permission and multi user
#
# 2010-04-08
SCRIPT_NAME = "grep"
SCRIPT_AUTHOR = "Elián Hanisch <lambdae2@gmail.com>"
-SCRIPT_VERSION = "0.8.1"
+SCRIPT_VERSION = "0.8.2"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Search in buffers and logs"
SCRIPT_COMMAND = "grep"
def get_matches_count(self):
"""Return the sum of total matches stored."""
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:
return 0
def __len__(self):
"""Return the sum of total lines stored."""
if dict.__len__(self):
- return sum(map(len, self.itervalues()))
+ return sum(map(len, self.values()))
else:
return 0
"""Returns buffer count or buffer name if there's just one stored."""
n = len(self.keys())
if n == 1:
- return self.keys()[0]
+ return list(self.keys())[0]
elif n > 1:
return '%s logs' %n
else:
def items(self):
"""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]))
return items
def items_count(self):
"""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)
return items
def strip_separator(self):
- for L in self.itervalues():
+ for L in self.values():
L.strip_separator()
def get_last_lines(self, n):
if n >= total_lines:
# nothing to do
return
- for k, v in reversed(self.items()):
+ for k, v in reversed(list(self.items())):
l = len(v)
if n > 0:
if l > n:
return cache_dir[key]
except KeyError:
pass
-
+
filter_list = filter_list or get_config_log_filter()
dir_len = len(dir)
if filter_list:
regexp = re.compile(pattern, re.IGNORECASE)
else:
regexp = re.compile(pattern)
- except Exception, e:
- raise Exception, 'Bad pattern, %s' %e
+ except Exception as e:
+ raise Exception('Bad pattern, %s' % e)
return regexp
def check_string(s, regexp, hilight='', exact=False):
return s
else:
check = lambda s: check_string(s, regexp, hilight, exact)
-
+
try:
file_object = open(file, 'r')
except IOError:
before_context, after_context = after_context, 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()
limit = tail or head
while id < after_context + offset:
id += 1
try:
- context_line = file_object.next()
+ context_line = next(file_object)
_context_line = check(context_line)
if _context_line:
offset = id
global grep_options, log_pairs
for log_name, log in log_pairs:
result[log_name] = grep_file(log, *grep_options)
- except Exception, e:
+ except Exception as e:
result = e
return pickle.dumps(result)
if isinstance(data, Exception):
raise data
matched_lines.update(data)
- except Exception, e:
+ except Exception as e:
set_buffer_error(repr(e))
return WEECHAT_RC_OK
else:
# free matched_lines so it can be removed from memory
del matched_lines
-
+
def split_line(s):
"""Splits log's line 's' in 3 parts, date, nick and msg."""
global weechat_format
weechat.infolist_free(infolist)
try:
cmd_grep_parsing(input_data)
- except Exception, e:
- error('Argument error, %s' %e, buffer=buffer)
+ except Exception as e:
+ error('Argument error, %s' % e, buffer=buffer)
return WEECHAT_RC_OK
try:
show_matching_lines()
- except Exception, e:
+ except Exception as e:
error(e)
except NameError:
error("There isn't any previous search to repeat.", buffer=buffer)
args = ' '.join(args) # join pattern for keep spaces
if args:
- pattern_tmpl = args
+ pattern_tmpl = args
pattern = _tmplRe.sub(tmplReplacer, args)
debug('Using regexp: %s', 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):
try:
opt = '-' + opt
else:
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:
opt = opt.strip('-')
# parse
try:
cmd_grep_parsing(args)
- except Exception, e:
- error('Argument error, %s' %e)
+ except Exception as e:
+ error('Argument error, %s' % e)
return WEECHAT_RC_OK
# find logs
# grepping
try:
show_matching_lines()
- except Exception, e:
+ except Exception as e:
error(e)
return WEECHAT_RC_OK
opt = opt.strip('-')
if opt in ('size', 's'):
sort_by_size = True
- except Exception, e:
- error('Argument error, %s' %e)
+ except Exception as e:
+ error('Argument error, %s' % e)
return WEECHAT_RC_OK
# is there's a filter, filter_excludes should be False
'completion_grep_args', '')
# settings
- for opt, val in settings.iteritems():
+ for opt, val in settings.items():
if not weechat.config_is_set_plugin(opt):
weechat.config_set_plugin(opt, val)
color_summary = weechat.color('lightcyan')
color_delimiter = weechat.color('chat_delimiters')
color_script_nick = weechat.color('chat_nick')
-
+
# pretty [grep]
script_nick = '%s[%s%s%s]%s' %(color_delimiter, color_script_nick, SCRIPT_NAME, color_delimiter,
color_reset)