]>
git.sthu.org Git - shutils.git/blob - dotfiles/irssi/scripts/niq.pl
1 # BitchX TAB complete style
2 # for irssi 0.7.99 by bd@bc-bd.org
4 # <tab> signal handling learned from dictcomplete by Timo Sirainen
6 # thx go out to fuchs, darix, dg, peder and all on #irssi who helped
12 # In a channel window type "ab<tab>" to see a list of nicks starting
14 # If you now press <tab> again, irssi will default to its own nick
16 # If you enter more characters you can use <tab> again to see a list
17 # of the matching nicks, or to complete the nick if there is only
20 # The last completion is saved so if you press "<tab>" with an empty
21 # input line, you get the last completed nick.
23 # Now there is a statusbar item where you can see the completing
24 # nicks instead of in the channel window. There are two ways to
27 # 1) Inside another statusbar
29 # /set niq_show_in_statusbar ON
30 # /statusbar window add -before more niq
32 # 2) In an own statusbar
34 # /statusbar niq enable
35 # /statusbar niq add niq
36 # /statusbar niq disable
37 # /set niq_show_in_statusbar ON
38 # /set niq_own_statusbar ON
40 # You can also hide the bar when not completing nicks by using
42 # /set niq_hide_on_inactive ON
48 # /set niq_show_in_statusbar <ON|OFF>
49 # * ON : show the completing nicks in a statusbar item
50 # * OFF : show the nicks in the channel window
52 # /set niq_own_statusbar <ON|OFF>
53 # * ON : use an own statusbar for the nicks
54 # * OFF : just use an item
56 # /set niq_hide_on_inactive <ON|OFF>
57 # * ON : hide the own statusbar on inactivity
58 # * OFF : dont hide it
60 # /set niq_color_char <ON|OFF>
61 # * ON : colors the next unlikely character
62 # * OFF : boring no colors
70 # - use configured completion_char instead of a colon
71 # - removed old, unused code
73 # - fixed documentation leading to emtpy statusbar
74 # - removed warning about a problem with irssi version 0.8.4
77 # - work around an use problem
80 # - fixed completion for nicks starting with special chars
83 # - removed unneeded sort() of colored nicks
84 # - moved colored nick generation to where it is needed
85 # - the statusbar only worked with colorized nicks (duh!)
88 # - stop nickcompleting if last char is the completion_char
89 # which is in most cases ':'
92 # - fixed vanishing statusbar. it wrongly was reset on any
96 # - changed statusbar to be off by default since most people
97 # dont use the latest fixed version.
100 # - added own statusbar option
101 # - added color char option
104 # - added an niq statusbar
107 # - added default to irssi method on <tab><tab>
110 # - added lastcomp support
121 use vars
qw($VERSION %IRSSI);
126 contact=> 'bd@bc-bd.org',
128 description=> 'BitchX like Nickcompletion at line start plus statusbar',
130 url=> 'https://bc-bd.org/cgi-bin/gitweb.cgi?p=irssi.git;a=summary',
133 my($lastword,$lastcomp,$niqString);
138 # build our nick with completion_char, add to complist and stop the signal
139 sub buildNickAndStop {
140 my ($complist,$nick) = @_;
141 my $push = $nick.Irssi::settings_get_str('completion_char');
145 push (@{$complist}, $push);
147 if (Irssi::settings_get_bool('niq_show_in_statusbar') == 1) {
151 Irssi::signal_stop();
156 my ($complist, $window, $word, $linestart, $want_space) = @_;
158 # still allow channel- #<tab>, /set n<tab>, etc completion.
159 if ($linestart ne "") {
163 # also back out if nothing has been entered and lastcomp is ""
165 if ($lastcomp ne "") {
166 buildNickAndStop($complist,$lastcomp);
172 if (rindex($word,Irssi::settings_get_str('completion_char')) == length($word) -1) {
174 buildNickAndStop($complist,$word,0);
178 my $channel = $window->{active};
180 # the completion is ok if this is a channel
181 if ($channel->{type} ne "CHANNEL")
188 # get the matching nicks but quote this l33t special chars like ^
189 my $shortestNick = 999;
190 my $quoted = quotemeta $word;
191 foreach my $n ($channel->nicks()) {
192 if ($n->{nick} =~ /^$quoted/i && $window->{active_server}->{nick} ne $n->{nick}) {
193 push(@nicks,$n->{nick});
194 if (length($n->{nick}) < $shortestNick) {
195 $shortestNick = length($n->{nick});
200 @nicks = sort(@nicks);
202 # if theres only one nick return it.
203 if (scalar @nicks eq 1)
205 buildNickAndStop($complist,$nicks[0]);
206 } elsif (scalar @nicks gt 1) {
207 # check if this is <tab> or <tab><tab>
208 if ($lastword eq $word) {
209 # <tab><tab> so default to the irssi method
212 $_ .= Irssi::settings_get_str ('completion_char');
215 push (@{$complist}, @nicks);
217 # but delete lastword to be ready for the next <tab>
220 if (Irssi::settings_get_bool('niq_show_in_statusbar') == 1) {
226 # <tab> only so just print
228 # build string w/o colored nicks
229 if (Irssi::settings_get_bool('niq_color_char') == 1) {
231 foreach my $n (@nicks) {
232 my $coloredNick = $n;
233 $coloredNick =~ s/($quoted)(.)(.*)/$1%_$2%_$3/i;
234 $niqString .= "$coloredNick ";
237 $niqString = join(" ",@nicks);
240 if (Irssi::settings_get_bool('niq_show_in_statusbar') == 1) {
241 drawStatusbar($niqString);
243 $window->print($niqString);
246 Irssi::signal_stop();
262 sub drawStatusbar() {
265 if (Irssi::settings_get_bool('niq_own_statusbar') == 1) {
266 if (Irssi::settings_get_bool('niq_hide_on_inactive') == 1) {
268 Irssi::command("statusbar niq disable");
270 Irssi::command("statusbar niq enable");
275 $niqString = "{sb $word}";
276 Irssi::statusbar_items_redraw('niq');
280 my ($item, $get_size_only) = @_;
282 $item->default_handler($get_size_only, $niqString, undef, 1);
285 Irssi::signal_add_first('complete word', 'sig_complete');
286 Irssi::signal_add_last('window changed', 'emptyBar');
287 Irssi::signal_add('message own_public', 'emptyBar');
289 Irssi::statusbar_item_register('niq', '$0', 'niqStatusbar');
290 Irssi::statusbars_recreate_items();
292 Irssi::settings_add_bool('misc', 'niq_show_in_statusbar', 0);
293 Irssi::settings_add_bool('misc', 'niq_own_statusbar', 0);
294 Irssi::settings_add_bool('misc', 'niq_hide_on_inactive', 1);
295 Irssi::settings_add_bool('misc', 'niq_color_char', 1);