]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Add autonickprefix.pl sscipt
authorJuerd Waalboer <redacted>
Tue, 12 Jan 2016 14:11:36 +0000 (15:11 +0100)
committerJuerd Waalboer <redacted>
Tue, 12 Jan 2016 14:11:36 +0000 (15:11 +0100)
scripts/autonickprefix.pl [new file with mode: 0644]

diff --git a/scripts/autonickprefix.pl b/scripts/autonickprefix.pl
new file mode 100644 (file)
index 0000000..5b9d656
--- /dev/null
@@ -0,0 +1,36 @@
+our $VERSION = '1.00';
+our %IRSSI = (
+    authors     => 'Juerd',
+    contact     => '#####@juerd.nl',
+    name        => 'autonickprefix',
+    description => "Change 'nick: ' prefix if the nick is changed while you're still editing.",
+    license     => 'Any OSI',
+);
+
+use Irssi qw(
+    signal_add active_win settings_get_str parse_special 
+    gui_input_get_pos gui_input_set gui_input_set_pos
+);
+
+signal_add 'nicklist changed' => sub {
+    my ($chan, $newnick, $oldnick) = @_;
+    $newnick = $newnick->{nick};
+
+    # Ignore other channels than current
+    my $viewing = active_win->{active} or return;
+    $viewing->{_irssi} == $chan->{_irssi} or return;
+
+    my $char  = settings_get_str 'completion_char';
+    my $pos   = gui_input_get_pos;
+
+    # Incomplete nick could be something else.
+    $pos >= length("$oldnick$char") or return;
+
+    my $delta = length($newnick) - length($oldnick);
+
+    my $input = parse_special '$L';
+    $input =~ s/^\Q$oldnick$char/$newnick$char/ or return;
+
+    gui_input_set     $input;
+    gui_input_set_pos $pos + $delta;
+};
git clone https://git.99rst.org/PROJECT