summaryrefslogtreecommitdiff
path: root/irssi/scripts
diff options
context:
space:
mode:
authorcos <cos>2022-10-02 23:58:50 +0200
committercos <cos>2022-10-02 23:58:50 +0200
commite0330cb6feb7800608186d9374a99a9f6ab5dd63 (patch)
treec8154189e006c00ef03a30bb4f8efbfaae825787 /irssi/scripts
downloadmicmot-e0330cb6feb7800608186d9374a99a9f6ab5dd63.zip
Initial commitHEADmain
Diffstat (limited to 'irssi/scripts')
-rw-r--r--irssi/scripts/micmot.pl90
1 files changed, 90 insertions, 0 deletions
diff --git a/irssi/scripts/micmot.pl b/irssi/scripts/micmot.pl
new file mode 100644
index 0000000..1ff8f87
--- /dev/null
+++ b/irssi/scripts/micmot.pl
@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+#
+# Irssi script to display buffer activity in tmux pane name.
+#
+# Ideally one single feature complete chat client should be used, but this
+# workaround makes life a bit more bearably in our contemporary world requiring
+# multiple chat clients.
+#
+# Requires something like: `F=~/.irssi/micmot-fifo; mkfifo $F; tail -f $F &`
+#
+# Also requires ":set-option allow-rename on" in the tmux buffer.
+
+use strict;
+use vars qw ($VERSION %IRSSI);
+use 5.32.0;
+
+use Irssi;
+
+$VERSION = '0.1.0';
+%IRSSI = (
+ authors => 'cos',
+ contact => '|cos|',
+ description => 'Abusing tmux pane names for displaying channel activity.',
+ license => 'MIT',
+ name => 'micmot',
+);
+
+my $TMUX_FIFO = $ENV{'IRSSI_TMUX_FIFO'};
+$TMUX_FIFO = $ENV{'HOME'}.'/.irssi/micmot-fifo' unless $TMUX_FIFO;
+
+my $PANE_NAME = $ENV{'IRSSI_TMUX_PANE'};
+$PANE_NAME = 'irssi' unless $PANE_NAME;
+
+sub set_pane_title {
+ my ( $title ) = @_;
+
+ my $FILE_HANDLE;
+ open $FILE_HANDLE, '>>', $TMUX_FIFO or return;
+ printf($FILE_HANDLE "%c]2;%s%c\\", 0x1b, $title, 0x1b);
+ close $FILE_HANDLE;
+}
+
+sub set_pane_name {
+ my ( $name ) = @_;
+
+ my $FILE_HANDLE;
+ open $FILE_HANDLE, '>>', $TMUX_FIFO or return;
+ printf($FILE_HANDLE "%ck%s%c\\", 0x1b, $name, 0x1b);
+ close $FILE_HANDLE;
+}
+
+sub highlight_pane {
+ my $FILE_HANDLE;
+ open $FILE_HANDLE, '>>', $TMUX_FIFO or return;
+ printf($FILE_HANDLE "\x07");
+ close $FILE_HANDLE;
+}
+
+sub activity_to_tmux {
+ my $active_win = Irssi::active_win() or return;
+ my $active_win_refnum = $active_win->{'refnum'} or return;
+
+ my @windows = Irssi::windows() or return;
+ my $tmux = "";
+ for ( @windows ) {
+ # Skip the currently active window.
+ next if $_->{'refnum'} eq $active_win_refnum;
+
+ # Include any windows with data_level 'msg' or 'highlight'.
+ if ($_->{'active'}->{'data_level'} ge 2) {
+ if (length($tmux) > 0) {
+ $tmux .= ",";
+ }
+ $tmux .= $_->{'active'}->{'visible_name'};
+ }
+ }
+
+ set_pane_name( $tmux ? "[" . $tmux =~ s/[^.,#0-9A-Za-z-]+//rg . "]" :
+ $PANE_NAME );
+ if ( $tmux ) {
+ highlight_pane();
+ }
+}
+
+say qq($IRSSI{name} $VERSION using "$TMUX_FIFO");
+set_pane_name( $PANE_NAME );
+set_pane_title( $PANE_NAME );
+
+Irssi::signal_add 'window activity' => \&activity_to_tmux;
+Irssi::signal_add 'window changed' => \&activity_to_tmux;