From: Rocco Caputo Date: Wed, 13 Oct 2010 21:31:44 +0000 (-0400) Subject: People in freenode #irssi have taken an interest, so get it to a public repository. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=9735a7b64ed1b5402fd1bbc79308abd47b6c9500;p=irssi-scripts.irssi.org.git People in freenode #irssi have taken an interest, so get it to a public repository. --- diff --git a/scripts/ack.pl b/scripts/ack.pl new file mode 100644 index 0000000..ea2d278 --- /dev/null +++ b/scripts/ack.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl +# vim: ts=2 sw=2 expandtab + +# Ack: Jump to the next active window, with tiebreakers. + +use warnings; +use strict; + +use Irssi; + +### Script header. + +our $VERSION = '1.000'; + +use vars qw(%IRSSI); +%IRSSI = ( + name => 'ack', + authors => 'Rocco Caputo', + contact => 'rcaputo@cpan.org', + url => 'http://github.com/rcaputo/irssi-ack', + license => 'Perl', + description => 'Jump to the next active window, with tiebreakers.', +); + +# Jump to an active channel. + +sub cmd_ack { + my ($cmd, $server, $window) = @_; + + # We sort the data_level in reverse order because higher numbers + # mean "more important". If the data_level is equal between two + # windows, then we jump to the window that has been upbated least + # recently. + # + # Currently that's the window with the earliest (oldest) last line + # of text. + + my @windows = sort { + ($b->{data_level} <=> $a->{data_level}) || + ($a->{last_line} <=> $b->{last_line} ) + } + grep { $_->{data_level} } # Must have some activity. + Irssi::windows(); + + # Jump to the first window. How hard can it be? + $windows[0]->set_active() if @windows; +} + +# Usage: /ack ... probably bind it to Meta-A or something. +Irssi::command_bind("ack", "cmd_ack");