use strict; use warnings; use vars qw($VERSION %IRSSI); use Irssi 20020324; { our $VERSION = "0.01"; our %IRSSI = ( name => "tag", description => "'/tag servertag /command' runs that /command with servertag as the active server", url => "http://explodingferret.com/linux/tag.pl", authors => "ferret", contact => "ferret(tA)explodingferret(moCtoD)", licence => "Public Domain", changed => "2007-10-10", changes => "", modules => "", commands => "tag", ); our $k = Irssi::parse_special( '$k' ); # command start character, usually / our $tagre = qr/^\Q${k}\Etag\b/io; } sub sig_complete_tag { my ( $complist, $windowrec, $word, $linestart, $want_space ) = @_; our ( $k, $tagre ); return unless $linestart =~ $tagre; if ( $linestart =~ s/^$tagre [^ ]+ *// ) { # if the first argument is present, remove it and trailing space # support "/tag servtag command" and "/tag servtag /command" if ( $linestart eq '' ) { index( $word, $k ) == 0 or $word = "$k$word"; } else { index( $linestart, $k ) == 0 or $linestart = "$k$linestart"; } # Segmentation fault (bug #534) :( # Irssi::signal_continue( $complist, $windowrec, $word, $linestart, $want_space ); Irssi::print "ferret.pl/tag: now: '$linestart' '$word'"; } else { # tab complete the first argument @$complist = grep /^\Q${word}\E/i, map( $_->{tag}, Irssi::servers ); Irssi::signal_stop(); } } sub cmd_tag { my ( $servtag, $command ) = split ' ', $_[0], 2; unless( defined $servtag and defined $command ) { Irssi::print "ferret.pl/tag: Usage: /tag server command"; return; } my $server = Irssi::server_find_tag( $servtag ); unless( $server ) { Irssi::print "ferret.pl/tag: Unknown server tag $servtag"; return; } $server->command( $command ); } Irssi::print "$IRSSI{name} version $VERSION loaded."; Irssi::signal_add_first( 'complete word' => \&sig_complete_tag ); Irssi::command_bind( 'tag' => \&cmd_tag );