From: vague666 Date: Sat, 26 Sep 2020 21:09:04 +0000 (+0200) Subject: [copy.pl] Added copy of several rows X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=6e8282fe146670f9ac74be86d476ef9323eeae88;p=irssi-scripts.irssi.org.git [copy.pl] Added copy of several rows requested updates remove aref suggestions from krytarik last one with spaces instead of tabs resolve review comments --- diff --git a/scripts/copy.pl b/scripts/copy.pl index 860b398..7b1e6e2 100644 --- a/scripts/copy.pl +++ b/scripts/copy.pl @@ -7,7 +7,7 @@ use Irssi::TextUI; use MIME::Base64; use File::Glob qw/:bsd_glob/; -$VERSION = '0.05'; +$VERSION = '0.10'; %IRSSI = ( authors => 'vague,bw1', contact => 'bw1@aol.at', @@ -15,7 +15,7 @@ $VERSION = '0.05'; description => 'copy a line in a paste buffer', license => 'Public Domain', url => 'https://scripts.irssi.org/', - changed => '2020-01-02', + changed => '2020-09-26', modules => 'MIME::Base64 File::Glob', commands=> 'copy', ); @@ -26,7 +26,7 @@ my $help = << "END"; %9Version%9 $VERSION %9Synopsis%9 - /copy [number] + /copy [start [end]] /copy <-f word> %9Description%9 $IRSSI{description} @@ -102,21 +102,33 @@ sub cmd_find { sub cmd_num { my ($args, $server, $witem)=@_; my $line=Irssi::active_win->view->{buffer}{cur_line}; - $args=1 if ($args==0); - $args=$args-1; unless (defined $line) { Irssi::print('No Copy!', MSGLEVEL_CLIENTCRAP); return(); } - for(1..$args) { - my $l=$line->prev; - if (defined $l) { - $line= $l; - } else { - last; - } + + my @arg = split /[\s-]/, $args; + if(@arg > 2 || grep {/[^\d]+/} @arg) { + Irssi::print('Illegal range!', MSGLEVEL_CLIENTCRAP); + return(); + } + + $arg[0] = 1 if ($arg[0]==0); + $arg[0] -= 1; + $arg[1] -= 1 if defined $arg[1]; + + for(1..$arg[0]) { + last unless $line->prev; + $line = $line->prev; + } + + my $str; + for($arg[0]..($arg[1] // $arg[0])) { + $str = join $copy_file_eol, $line->get_text(0), $str; + + last unless $line->prev; + $line = $line->prev; } - my $str=$line->get_text(0); paste ($str); }