summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2015-05-29 14:09:55 +0200
committerailin-nemui <ailin-nemui@users.noreply.github.com>2015-05-29 14:09:55 +0200
commitfa782ae6bce1efd19f41f3b225e13e390d7629b2 (patch)
tree1e23b5a0a399a087955e8d47b8fdbd768a2f753b /scripts
parentc122a2a226363114e11f32072395e2f06ad6a450 (diff)
downloadirssi-fa782ae6bce1efd19f41f3b225e13e390d7629b2.zip
Update sb_search.pl
make it easier to bind sb search to a key
Diffstat (limited to 'scripts')
-rw-r--r--scripts/sb_search.pl51
1 files changed, 34 insertions, 17 deletions
diff --git a/scripts/sb_search.pl b/scripts/sb_search.pl
index 43fc7b55..51b9100b 100644
--- a/scripts/sb_search.pl
+++ b/scripts/sb_search.pl
@@ -22,7 +22,7 @@ use Irssi;
use Irssi::TextUI;
use vars qw($VERSION %IRSSI);
-$VERSION = '1.0';
+$VERSION = '1.1';
%IRSSI = (
authors => 'Wouter Coekaerts, Emanuele Giaquinta',
contact => 'wouter@coekaerts.be, exg@irssi.org',
@@ -40,49 +40,66 @@ sub cmd_help {
SCROLLBACK SEARCH [-level <level>] [-regexp] [-case] [-word] [-forward] [-all] [<pattern>]
- -level: only search for lines with the given level. see /help levels
- -regexp: the pattern is a regular expression
- -case: search case sensitive
- -word: pattern must match to full words
- -forward: search forwards (default is backwards)
- -all: search in all windows
- <pattern>: text to search for
+ SEARCH: Search for text in the scrollback buffer.
+
+ -regexp: The given text pattern is a regular expression.
+ -case: Performs a case-sensitive matching.
+ -word: The text must match full words.
+ -forward: Search forwards (default is backwards).
+ -all: Search in all windows.
+
+ Without arguments, the last search is repeated.
SCRIPTHELP_EOF
,MSGLEVEL_CLIENTCRAP);
}
}
+my $regex;
+my $all;
+my $level;
-sub cmd_sb_search ($$$) {
+sub cmd_sb_search {
my ($args, $server, $witem) = @_;
### handle options
my ($options, $pattern) = Irssi::command_parse_options('scrollback search', $args);
- my $level;
+ my $forward = defined(delete $options->{forward});
+
+ if (!%$options && !$pattern) {
+ return if !$regex && !defined $level;
+ } else {
+ $all = defined($options->{all});
+ $level = MSGLEVEL_ALL;
+ undef $regex;
+ }
+
if (defined($options->{level})) {
$level = $options->{level};
$level =~ y/,/ /;
$level = Irssi::combine_level(0, $level);
- } else {
- return if (!$pattern);
- $level = MSGLEVEL_ALL;
}
- my $regex;
if ($pattern) {
my $flags = defined($options->{case}) ? '' : '(?i)';
my $b = defined($options->{word}) ? '\b' : '';
if (defined($options->{regexp})) {
- $regex = qr/$flags$b$pattern$b/;
+ local $@;
+ eval {
+ $regex = qr/$flags$b$pattern$b/;
+ };
+ if ($@) {
+ my ($err) = $@ =~ /^(.*)/;
+ $err =~ s/\sat .* line \d+\.$//;
+ print CLIENTERROR $err;
+ return;
+ }
} else {
$regex = qr/$flags$b\Q$pattern\E$b/;
}
}
- my $forward = defined($options->{forward});
- my $all = defined($options->{all});
### determine window(s) to search in