diff options
author | cos <cos> | 2022-10-02 23:58:50 +0200 |
---|---|---|
committer | cos <cos> | 2022-10-02 23:58:50 +0200 |
commit | e0330cb6feb7800608186d9374a99a9f6ab5dd63 (patch) | |
tree | c8154189e006c00ef03a30bb4f8efbfaae825787 /weechat/python | |
download | micmot-main.zip |
Diffstat (limited to 'weechat/python')
-rw-r--r-- | weechat/python/micmot.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/weechat/python/micmot.py b/weechat/python/micmot.py new file mode 100644 index 0000000..e1a77b3 --- /dev/null +++ b/weechat/python/micmot.py @@ -0,0 +1,82 @@ +#!/usr/bin/python3 +# +# Weechat script to display buffer actitity in tmux pane name. +# +# A workaround for: https://github.com/weechat/weechat/issues/741 +# +# Ideally weechat should support multiple hotlists, to make it possible to +# logically separate different chats into groups. Since such a feature is +# missing, and implementing it would be non-trivial, this script helps if +# running multiple weechat instances within a tmux. It abuses the ability to +# rename pane to make them double as channel activity indicators. +# +# Requires something like: `F=~/.weechat/micmot-fifo; mkfifo $F; tail -f $F &` +# +# Also requires ":set-option allow-rename on" in the tmux buffer. + +import os +import re +import weechat + +TMUX_FIFO = os.environ.get('WEECHAT_TMUX_FIFO', + os.environ['HOME'] + '/.weechat/micmot-fifo') + +PANE_NAME = os.environ.get('WEECHAT_TMUX_PANE', 'weechat') + +weechat.register( + "micmot", + "|cos|", + "0.1.0", + "MIT", + "Abusing tmux pane names for displaying channel activity.", + "", + "" +) + +def set_pane_name(name): + with open(TMUX_FIFO,'a') as f: + f.write("\x1bk%s\x1b\\" % name) + +def highlight_pane(): + with open(TMUX_FIFO,'a') as f: + f.write("\x07") + +def set_pane_title(name): + with open(TMUX_FIFO, 'a') as f: + f.write("\x1b]2;%s\x1b\\" % name) + +def hotlist_cb(a, b, c): + # https://weechat.org/files/doc/stable/weechat_user.en.html#notify_levels + tmux = "" + infolist = weechat.infolist_get("hotlist", "", "") + while weechat.infolist_next(infolist) != 0: + buffer_name = weechat.infolist_string(infolist, "buffer_name") + plugin_name = weechat.infolist_string(infolist, "plugin_name") + needle_pointer = weechat.buffer_search(plugin_name, buffer_name) + if needle_pointer: + short = weechat.buffer_get_string(needle_pointer, "short_name") + count_01 = weechat.infolist_integer(infolist, "count_01") + count_02 = weechat.infolist_integer(infolist, "count_02") + count_03 = weechat.infolist_integer(infolist, "count_03") + if count_01 > 0 or count_02 > 0 or count_03 > 0: + if tmux: + tmux = "{},{}".format(tmux,short) + else: + tmux = "{}".format(short) + else: + weechat.prnt("", "No buffer matching {} for plugin {}." + .format(buffer_name, plugin_name)) + + if tmux: + set_pane_name("[{}]".format(re.sub(r'[^.,#0-9A-Za-z-]+', '', tmux))) + highlight_pane() + else: + set_pane_name(PANE_NAME) + + weechat.infolist_free(infolist) + return weechat.WEECHAT_RC_OK + +weechat.prnt("", "micmot " + PANE_NAME + TMUX_FIFO) +set_pane_name(PANE_NAME) +set_pane_title(PANE_NAME) +weechat.hook_signal("hotlist_changed", "hotlist_cb", "") |