html/go.pl
1 use strict;
2 use vars qw($VERSION %IRSSI);
3 use Irssi;
4 use Irssi::Irc;
5
6 # Usage:
7 # /script load go.pl
8 # If you are in #irssi you can type /go #irssi or /go irssi or even /go ir ...
9 # also try /go ir<tab> and /go <tab> (that's two spaces)
10
11 $VERSION = '1.00';
12
13 %IRSSI = (
14 authors => 'nohar',
15 contact => 'nohar@freenode',
16 name => 'go to window',
17 description => 'Implements /go command that activates a window given a name/partial name. It features a nice completion.',
18 license => 'GPLv2 or later',
19 changed => '08-17-04'
20 );
21
22 sub signal_complete_go {
23 my ($complist, $window, $word, $linestart, $want_space) = @_;
24 my $channel = $window->get_active_name();
25 my $k = Irssi::parse_special('$k');
26
27 return unless ($linestart =~ /^\Q${k}\Ego/i);
28
29 @$complist = ();
30 foreach my $w (Irssi::windows) {
31 my $name = $w->get_active_name();
32 if ($word ne "") {
33 if ($name =~ /\Q${word}\E/i) {
34 push(@$complist, $name)
35 }
36 } else {
37 push(@$complist, $name);
38 }
39 }
40 Irssi::signal_stop();
41 };
42
43 sub cmd_go
44 {
45 my($chan,$server,$witem) = @_;
46
47 $chan =~ s/ *//g;
48 foreach my $w (Irssi::windows) {
49 my $name = $w->get_active_name();
50 if ($name =~ /^#?\Q${chan}\E/) {
51 $w->set_active();
52 return;
53 }
54 }
55 }
56
57 Irssi::command_bind("go", "cmd_go");
58 Irssi::signal_add_first('complete word', 'signal_complete_go');
59