# Windowtidy by James "JamesOff" Seward # # Extended by dive: # Added setting to autoclose windows with no names: # /set windowtidy_auto ON/OFF # dive - dave@unrealize.co.uk # use strict; use Irssi; use vars qw{%IRSSI $VERSION}; %IRSSI = ( name => 'windowtidy', authors => 'James Seward ,Dave Woodfall', contact => 'james@jamesoff.net, dave@unrealize.co.uk', url => 'http://jamesoff.net, http://www.unrealize.co.uk', description => 'Closes windows with no items in and no name. Added option to auto close.', license => 'BSD', changed => '2008-12-08', ); $VERSION = "1.1"; sub command_windowtidy { my($data,$server,$witem) = @_; my $count = 0; # need to iterate windows in reverse to stop their positions changing # on reflection I guess I could probably just get the size of the windows array and # count backwards from there, but it works now so meh :P my @windows = sort { $b <=> $a } map { $_->{refnum} } Irssi::windows(); foreach my $win (@windows) { my $window = Irssi::window_find_refnum($win); if (($window->{active} eq "") && ($window->{name} eq "")) { Irssi::command("window close $win"); $count++; } } # Irssi::print("Tidied away $count window(s)."); # don't really need to do this return; } sub auto_windowtidy { if( Irssi::settings_get_bool('windowtidy_auto') ) { command_windowtidy(); } } Irssi::settings_add_bool('windowtidy', 'windowtidy_auto', 0); Irssi::command_bind('windowtidy', 'command_windowtidy'); Irssi::signal_add_last('window changed automatic', 'auto_windowtidy');