summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--irssi/scripts/micmot.pl4
-rw-r--r--profanity/prof-micmot.py92
-rw-r--r--weechat/python/micmot.py6
4 files changed, 104 insertions, 3 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9bac453
--- /dev/null
+++ b/README.md
@@ -0,0 +1,5 @@
+# micmot
+
+## Multiple Irc Clients Multiplexed Over Tmux
+
+<https://blog.netizen.se/p/multiple-irc-clients-multiplexed-over-tmux/>
diff --git a/irssi/scripts/micmot.pl b/irssi/scripts/micmot.pl
index 1ff8f87..527329a 100644
--- a/irssi/scripts/micmot.pl
+++ b/irssi/scripts/micmot.pl
@@ -30,6 +30,7 @@ $TMUX_FIFO = $ENV{'HOME'}.'/.irssi/micmot-fifo' unless $TMUX_FIFO;
my $PANE_NAME = $ENV{'IRSSI_TMUX_PANE'};
$PANE_NAME = 'irssi' unless $PANE_NAME;
+my $PANE_MAXLEN = 30;
sub set_pane_title {
my ( $title ) = @_;
@@ -75,7 +76,8 @@ sub activity_to_tmux {
}
}
- set_pane_name( $tmux ? "[" . $tmux =~ s/[^.,#0-9A-Za-z-]+//rg . "]" :
+ $tmux =~ s/[^.,#0-9A-Za-z-]+//rg;
+ set_pane_name( $tmux ? "[" . $tmux =~ s/.{$PANE_MAXLEN}\K.*//s . "]" :
$PANE_NAME );
if ( $tmux ) {
highlight_pane();
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
diff --git a/weechat/python/micmot.py b/weechat/python/micmot.py
index e1a77b3..d6965b1 100644
--- a/weechat/python/micmot.py
+++ b/weechat/python/micmot.py
@@ -16,12 +16,13 @@
import os
import re
-import weechat
+import weechat # type: ignore
TMUX_FIFO = os.environ.get('WEECHAT_TMUX_FIFO',
os.environ['HOME'] + '/.weechat/micmot-fifo')
PANE_NAME = os.environ.get('WEECHAT_TMUX_PANE', 'weechat')
+PANE_MAXLEN = 30
weechat.register(
"micmot",
@@ -68,7 +69,8 @@ def hotlist_cb(a, b, c):
.format(buffer_name, plugin_name))
if tmux:
- set_pane_name("[{}]".format(re.sub(r'[^.,#0-9A-Za-z-]+', '', tmux)))
+ set_pane_name("[{}]".format(
+ re.sub(r'[^.,#0-9A-Za-z-]+', '', tmux[:PANE_MAXLEN])))
highlight_pane()
else:
set_pane_name(PANE_NAME)