summaryrefslogtreecommitdiff
path: root/.irssi
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2020-06-02 05:11:26 +0000
committerMike Crute <mike@crute.us>2020-06-02 05:11:33 +0000
commit5bd5206b3b00a982ab0509608dc85d6be03bd4c0 (patch)
treecc35df7ae0aaa0c664393ce4f9c2d19b52f24372 /.irssi
parent7d51c7d60ef8b8f7fb717a418945e6116df83032 (diff)
downloaddotfiles-5bd5206b3b00a982ab0509608dc85d6be03bd4c0.tar.bz2
dotfiles-5bd5206b3b00a982ab0509608dc85d6be03bd4c0.tar.xz
dotfiles-5bd5206b3b00a982ab0509608dc85d6be03bd4c0.zip
irssi: add scrollback search
Diffstat (limited to '.irssi')
l---------.irssi/scripts/autorun/sb_search.pl1
-rw-r--r--.irssi/scripts/sb_search.pl156
2 files changed, 157 insertions, 0 deletions
diff --git a/.irssi/scripts/autorun/sb_search.pl b/.irssi/scripts/autorun/sb_search.pl
new file mode 120000
index 0000000..5b0bc46
--- /dev/null
+++ b/.irssi/scripts/autorun/sb_search.pl
@@ -0,0 +1 @@
../sb_search.pl \ No newline at end of file
diff --git a/.irssi/scripts/sb_search.pl b/.irssi/scripts/sb_search.pl
new file mode 100644
index 0000000..d636ac4
--- /dev/null
+++ b/.irssi/scripts/sb_search.pl
@@ -0,0 +1,156 @@
1# sb_search.pl - search in your scrollback, scroll to a match
2# Do /HELP SCROLLBACK for help
3
4# Copyright (C) 2008 Wouter Coekaerts <wouter@coekaerts.be>, Emanuele Giaquinta <exg@irssi.org>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20use strict;
21use Irssi;
22use Irssi::TextUI;
23use vars qw($VERSION %IRSSI);
24
25$VERSION = '1.2';
26%IRSSI = (
27 authors => 'Wouter Coekaerts, Emanuele Giaquinta',
28 contact => 'wouter@coekaerts.be, exg@irssi.org',
29 name => 'sb_search',
30 description => 'search in your scrollback, scroll to a match',
31 license => 'GPLv2 or later',
32 url => 'http://wouter.coekaerts.be/irssi/',
33 changed => '$LastChangedDate$',
34);
35
36sub cmd_help {
37 my ($args, $server, $witem) = @_;
38 if ($args =~ /^scrollback( search)? *$/i) {
39 Irssi::print ( <<SCRIPTHELP_EOF
40
41SCROLLBACK SEARCH [-level <level>] [-regexp] [-case] [-word] [-forward] [-all] [<pattern>]
42
43 SEARCH: Search for text in the scrollback buffer.
44
45 -regexp: The given text pattern is a regular expression.
46 -case: Performs a case-sensitive matching.
47 -word: The text must match full words.
48 -forward: Search forwards (default is backwards).
49 -all: Search in all windows.
50
51 Without arguments, the last search is repeated.
52SCRIPTHELP_EOF
53 ,MSGLEVEL_CLIENTCRAP);
54 }
55}
56
57my $regex;
58my $all;
59my $level;
60
61sub cmd_sb_search {
62 my ($args, $server, $witem) = @_;
63
64 ### handle options
65
66 my ($options, $pattern) = Irssi::command_parse_options('scrollback search', $args);
67
68 my $forward = defined(delete $options->{forward});
69
70 if (!%$options && !$pattern) {
71 return if !$regex && !defined $level;
72 } else {
73 $all = defined($options->{all});
74 $level = MSGLEVEL_ALL;
75 undef $regex;
76 }
77
78 if (defined($options->{level})) {
79 $level = $options->{level};
80 $level =~ y/,/ /;
81 $level = Irssi::combine_level(0, $level);
82 }
83
84 if ($pattern) {
85 my $flags = defined($options->{case}) ? '' : '(?i)';
86 my $b = defined($options->{word}) ? '\b' : '';
87 if (defined($options->{regexp})) {
88 local $@;
89 eval {
90 $regex = qr/$flags$b$pattern$b/;
91 };
92 if ($@) {
93 my ($err) = $@ =~ /^(.*)/;
94 $err =~ s/\sat .* line \d+\.$//;
95 print CLIENTERROR $err;
96 return;
97 }
98 } else {
99 $regex = qr/$flags$b\Q$pattern\E$b/;
100 }
101 }
102
103
104 ### determine window(s) to search in
105
106 my $current_win = ref $witem ? $witem->window() : Irssi::active_win();
107
108 my @windows;
109 if ($all) {
110 # cycle backward or forwards over all windows starting from current
111 # for example, searching backward through 5 windows, with window 3 active: search order is 3,2,1,5,4
112 # if we're searching forward: 3,4,5,1,2
113 my $order = $forward ? 1 : -1;
114 @windows = sort {$order * ($a->{refnum} cmp $b->{refnum})} Irssi::windows();
115 my @before_windows = grep {($_->{refnum} cmp $current_win->{refnum}) == $order} @windows;
116 my @after_windows = grep {($_->{refnum} cmp $current_win->{refnum}) == -$order} @windows;
117 @windows = ($current_win, @before_windows, @after_windows);
118 } else {
119 @windows = ($current_win);
120 }
121
122 ### do the search
123
124 foreach my $win (@windows) {
125 my $view = $win->view;
126
127 ## determine line to start from
128 my $line;
129 if ($all && $win != $current_win) {
130 if ($forward) { # first line
131 $line = $view->get_lines;
132 } else { # last line
133 $line = $view->{buffer}{cur_line};
134 }
135 } elsif ($view->{startline}) { # line after or before first visible line
136 $line = $forward ? $view->{startline}->next : $view->{startline}->prev;
137 }
138
139 ## loop over the lines
140 while (defined $line) {
141 my $line_level = $line->{info}{level};
142 if ($line_level & $level && $line->get_text(0) =~ $regex) {
143 $view->scroll_line($line);
144 if ($all) {
145 Irssi::command('window goto ' . $win->{refnum});
146 }
147 return;
148 }
149 $line = $forward ? $line->next : $line->prev;
150 }
151 }
152}
153
154Irssi::command_bind('scrollback search', \&cmd_sb_search);
155Irssi::command_bind_last('help', \&cmd_help);
156Irssi::command_set_options('scrollback search', '-level regexp case word forward all');