File: go.pl-multiple-networks.diff

package info (click to toggle)
irssi-scripts 20160301
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,624 kB
  • ctags: 2,564
  • sloc: perl: 61,025; sh: 184; makefile: 6
file content (87 lines) | stat: -rw-r--r-- 2,459 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Description: show network name if there're channels with the same name on different networks
Forwarded: no
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=476518
Author: Ryan Niebur <ryanryan52@gmail.com>
Last-Update: 2009-05-12
--- a/scripts/go.pl
+++ b/scripts/go.pl
@@ -19,6 +19,48 @@ $VERSION = '1.01';
     changed     => '2014-10-19'
 );
 
+sub generate_the_list {
+  my $foo = {};
+  foreach(Irssi::windows) {
+    $foo->{get_channel_name($_)} ||= 0;
+    $foo->{get_channel_name($_)} += 1;
+  }
+  return $foo;
+}
+
+sub get_server_tag {
+  my $w = shift;
+  if(defined($w->items()) && defined($w->items()->{server}) && defined($w->items()->{server}->{tag})) {
+    return $w->items()->{server}->{tag};
+  } else {
+    return "";
+  }
+}
+
+sub get_channel_name {
+  my $w = shift;
+  return $w->get_active_name();
+}
+
+sub get_channel_and_tag {
+  my $w = shift;
+  if(length(get_server_tag($w)) > 0) {
+    return get_channel_name($w) . '@' . get_server_tag($w);
+  } else {
+    return get_channel_name($w); # dunno how to handle this correctly...hopefully it will never come up.
+  }
+}
+
+sub name_of_this_window {
+  my $w = shift;
+  my $list = generate_the_list();
+  if($list->{get_channel_name($w)} > 1){
+    return get_channel_and_tag($w);
+  } else {
+    return get_channel_name($w);
+  }
+}
+
 sub signal_complete_go {
 	my ($complist, $window, $word, $linestart, $want_space) = @_;
 	my $channel = $window->get_active_name();
@@ -28,7 +70,7 @@ sub signal_complete_go {
 
 	@$complist = ();
 	foreach my $w (Irssi::windows) {
-		my $name = $w->get_active_name();
+		my $name = name_of_this_window($w);
 		if ($word ne "") {
 			if ($name =~ /\Q${word}\E/i) {
 				push(@$complist, $name)
@@ -45,8 +87,20 @@ sub cmd_go
 	my($chan,$server,$witem) = @_;
 
 	$chan =~ s/ *//g;
+        # try an exact match first ... this fixes when there are cases
+        # like a channel called #foo and #foobar, #foobar is above
+        # #foo in irssi's list, and the user types in #foo. before
+        # they would have ended up at #foobar instead of #foo. now
+        # they will end up at #foo.
+	foreach my $w (Irssi::windows) {
+		my $name = name_of_this_window($w);
+		if ($name =~ /^#?\Q${chan}\E$/) {
+			$w->set_active();
+			return;
+		}
+	}
 	foreach my $w (Irssi::windows) {
-		my $name = $w->get_active_name();
+		my $name = name_of_this_window($w);
 		if ($name =~ /^#?\Q${chan}\E/) {
 			$w->set_active();
 			return;