diff options
author | Ben Harris <ben@tilde.team> | 2020-07-18 14:14:12 -0400 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2020-07-18 14:14:12 -0400 |
commit | b6a7d6446382af4db967ca7212efa2f591bfa268 (patch) | |
tree | e95d5e6d8dfda8207eae28a59ae93002a9a9d695 /weechat/.weechat/python | |
parent | 655cdf37df0560ebd28d2edba26e65278d82f637 (diff) |
update scripts and configs for weechat 2.9
Diffstat (limited to 'weechat/.weechat/python')
l--------- | weechat/.weechat/python/autoload/fzf.py | 1 | ||||
-rw-r--r-- | weechat/.weechat/python/colorize_nicks.py | 16 | ||||
-rw-r--r-- | weechat/.weechat/python/fzf.py | 74 | ||||
-rw-r--r-- | weechat/.weechat/python/grep.py | 30 |
4 files changed, 108 insertions, 13 deletions
diff --git a/weechat/.weechat/python/autoload/fzf.py b/weechat/.weechat/python/autoload/fzf.py new file mode 120000 index 0000000..b723ed3 --- /dev/null +++ b/weechat/.weechat/python/autoload/fzf.py @@ -0,0 +1 @@ +../fzf.py \ No newline at end of file diff --git a/weechat/.weechat/python/colorize_nicks.py b/weechat/.weechat/python/colorize_nicks.py index d0cdc0e..19be2fc 100644 --- a/weechat/.weechat/python/colorize_nicks.py +++ b/weechat/.weechat/python/colorize_nicks.py @@ -21,6 +21,9 @@ # # # History: +# 2020-05-09: Sébastien Helleu <flashcode@flashtux.org> +# version 27: add compatibility with new weechat_print modifier data +# (WeeChat >= 2.9) # 2018-04-06: Joey Pabalinas <joeypabalinas@gmail.com> # version 26: fix freezes with too many nicks in one line # 2018-03-18: nils_2 @@ -85,7 +88,7 @@ w = weechat SCRIPT_NAME = "colorize_nicks" SCRIPT_AUTHOR = "xt <xt@bash.no>" -SCRIPT_VERSION = "26" +SCRIPT_VERSION = "27" SCRIPT_LICENSE = "GPL" SCRIPT_DESC = "Use the weechat nick colors in the chat area" @@ -172,11 +175,16 @@ def colorize_cb(data, modifier, modifier_data, line): global ignore_nicks, ignore_channels, colored_nicks + if modifier_data.startswith('0x'): + # WeeChat >= 2.9 + buffer, tags = modifier_data.split(';', 1) + else: + # WeeChat <= 2.8 + plugin, buffer_name, tags = modifier_data.split(';', 2) + buffer = w.buffer_search(plugin, buffer_name) - full_name = modifier_data.split(';')[1] - channel = '.'.join(full_name.split('.')[1:]) + channel = w.buffer_get_string(buffer, 'localvar_channel') - buffer = w.buffer_search('', full_name) # Check if buffer has colorized nicks if buffer not in colored_nicks: return line diff --git a/weechat/.weechat/python/fzf.py b/weechat/.weechat/python/fzf.py new file mode 100644 index 0000000..c43f503 --- /dev/null +++ b/weechat/.weechat/python/fzf.py @@ -0,0 +1,74 @@ +from typing import Iterator, Tuple +import weechat + + +SCRIPT_NAME = "fzf" +SCRIPT_AUTHOR = "Trygve Aaberge <trygveaa@gmail.com>" +SCRIPT_VERSION = "0.1.0" +SCRIPT_LICENSE = "MIT" +SCRIPT_DESC = "Switch buffer using fzf (currently only works inside tmux)" +REPO_URL = "https://github.com/trygveaa/weechat-fzf" + + +def print_error(message: str) -> None: + weechat.prnt("", weechat.prefix("error") + message) + + +def fzf_process_cb( + data: str, command: str, return_code: int, out: str, err: str +) -> int: + if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR or return_code == 2 or err: + print_error("Error running fzf (code {}): {}".format(return_code, err)) + return weechat.WEECHAT_RC_OK + if out != "": + pointer, _ = out.split("\t", 1) + weechat.buffer_set(pointer, "display", "1") + return weechat.WEECHAT_RC_OK + + +def fzf_command_cb(data: str, buffer: str, args: str) -> int: + cmd = ( + "fzf-tmux -- --delimiter='\t' --with-nth=3.. " + "--preview='tail -$LINES {2} 2>/dev/null'" + ) + hook = weechat.hook_process_hashtable(cmd, {"stdin": "1"}, 0, "fzf_process_cb", "") + for buffer_info in buffers(): + weechat.hook_set(hook, "stdin", "\t".join(buffer_info) + "\n") + weechat.hook_set(hook, "stdin_close", "") + return weechat.WEECHAT_RC_OK + + +def buffers() -> Iterator[Tuple[str, str, str, str]]: + logger_filenames = {} + logger_infolist = weechat.infolist_get("logger_buffer", "", "") + while weechat.infolist_next(logger_infolist): + buffer = weechat.infolist_pointer(logger_infolist, "buffer") + filename = weechat.infolist_string(logger_infolist, "log_filename") + logger_filenames[buffer] = filename + weechat.infolist_free(logger_infolist) + + buffer_infolist = weechat.infolist_get("buffer", "", "") + while weechat.infolist_next(buffer_infolist): + pointer = weechat.infolist_pointer(buffer_infolist, "pointer") + number = weechat.infolist_integer(buffer_infolist, "number") + name = weechat.infolist_string(buffer_infolist, "name") + yield (pointer, logger_filenames.get(pointer, ""), str(number), name) + weechat.infolist_free(buffer_infolist) + + +def main() -> None: + if not weechat.register( + SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", "" + ): + return + + tmux = weechat.string_eval_expression("${env:TMUX}", {}, {}, {}) + if not tmux: + print_error("Error: fzf.py currently only supports being run inside tmux") + return + + weechat.hook_command(SCRIPT_NAME, SCRIPT_DESC, "", "", "", "fzf_command_cb", "") + + +if __name__ == "__main__": + main() diff --git a/weechat/.weechat/python/grep.py b/weechat/.weechat/python/grep.py index 64dbc52..c176ffe 100644 --- a/weechat/.weechat/python/grep.py +++ b/weechat/.weechat/python/grep.py @@ -69,6 +69,9 @@ # # History: # +# 2020-05-06, Dominique Martinet <asmadeus@codewreck.org> and hexa- +# version 0.8.3: more python3 compatibility fixes... +# # 2019-06-30, dabbill <dabbill@gmail.com> # and Sébastien Helleu <flashcode@flashtux.org> # version 0.8.2: make script compatible with Python 3 @@ -230,7 +233,7 @@ except ImportError: SCRIPT_NAME = "grep" SCRIPT_AUTHOR = "Elián Hanisch <lambdae2@gmail.com>" -SCRIPT_VERSION = "0.8.2" +SCRIPT_VERSION = "0.8.3" SCRIPT_LICENSE = "GPL3" SCRIPT_DESC = "Search in buffers and logs" SCRIPT_COMMAND = "grep" @@ -596,7 +599,10 @@ def get_file_by_name(buffer_name): if '$server' in mask: mask = mask.replace('$server', server) # change the unreplaced vars by '*' - from string import letters + try: + from string import letters + except ImportError: + from string import ascii_letters as letters if '%' in mask: # vars for time formatting mask = mask.replace('%', '$') @@ -984,7 +990,7 @@ def show_matching_lines(): buffer_update() else: global hook_file_grep, grep_stdout, grep_stderr, pattern_tmpl - grep_stdout = grep_stderr = '' + grep_stdout = grep_stderr = b'' hook_file_grep = weechat.hook_process( 'func:grep_process', get_config_int('timeout_secs') * 1000, @@ -1009,14 +1015,17 @@ def grep_process(*args): except Exception as e: result = e - return pickle.dumps(result) - -grep_stdout = grep_stderr = '' + return pickle.dumps(result, 0) def grep_process_cb(data, command, return_code, out, err): global grep_stdout, grep_stderr, matched_lines, hook_file_grep + if isinstance(out, str): + out = out.encode() grep_stdout += out + + if isinstance(err, str): + err = err.encode() grep_stderr += err def set_buffer_error(message): @@ -1548,7 +1557,7 @@ def cmd_logs(data, buffer, args): buffer = buffer_create() if get_config_boolean('clear_buffer'): weechat.buffer_clear(buffer) - file_list = zip(file_list, file_sizes) + file_list = list(zip(file_list, file_sizes)) msg = 'Found %s logs.' %len(file_list) print_line(msg, buffer, display=True) @@ -1738,8 +1747,11 @@ Examples: debug = pybuffer.debugBuffer(globals(), '%s_debug' % SCRIPT_NAME) except: def debug(s, *args): - if not isinstance(s, basestring): - s = str(s) + try: + if not isinstance(s, basestring): + s = str(s) + except NameError: + pass if args: s = s %args prnt('', '%s\t%s' %(script_nick, s)) |