diff options
Diffstat (limited to 'profanity/prof-micmot.py')
-rw-r--r-- | profanity/prof-micmot.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/profanity/prof-micmot.py b/profanity/prof-micmot.py new file mode 100644 index 0000000..c844f83 --- /dev/null +++ b/profanity/prof-micmot.py @@ -0,0 +1,92 @@ +""" +Profanity plugin to display buffer activity in tmux pane name. + +Requires something like: +`F=~/.local/share/profanity/micmot-fifo; mkfifo $F; tail -f $F &` + +Also requires ":set-option allow-rename on" in the tmux buffer. +""" + +import os +import re +from sys import platform +from typing import List + +# https://profanity-im.github.io/plugins/0.5.1/python/html/index.html +import prof # type: ignore + +TMUX_FIFO = os.environ.get('PROFANITY_TMUX_FIFO', + os.environ['HOME'] + '/.local/share/profanity/micmot-fifo') + +PANE_NAME = os.environ.get('PROFANITY_TMUX_PANE', 'profanity') +PANE_MAXLEN = 30 + +unread: List[str] = [] + + +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 update_pane_name(): + global unread + if len(unread) == 0: + set_pane_name(PANE_NAME) + else: + tmux = "" + for part in unread: + if tmux == "": + tmux = part + else: + tmux += "," + part + set_pane_name("[{}]".format( + re.sub(r'[^.,@#0-9A-Za-z-]+', '', tmux[:PANE_MAXLEN]))) + +def post_message_display(barejid, resource, message): + global unread + if barejid != prof.get_current_recipient(): + if not barejid in unread: + unread.append(barejid) + update_pane_name() + highlight_pane() + + +def prof_on_chat_win_focus(barejid): + global unread + if barejid in unread: + unread.remove(barejid) + update_pane_name() + + +def prof_post_chat_message_display(barejid, resource, message): + post_message_display(barejid, resource, message) + return message + + +def prof_post_room_message_display(barejid, nick, message): + post_message_display(barejid, resource, message) + return message + + +def prof_post_priv_message_display(barejid, nick, message): + post_message_display(barejid, resource, message) + return message + + +def prof_init(version, status, account_name, fulljid): + prof.cons_show("Started micmot." + PANE_NAME + TMUX_FIFO) + set_pane_name(PANE_NAME) + set_pane_title(PANE_NAME) + +# vim: ft=python |