1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/usr/bin/perl
use warnings;
use strict;
use Irssi qw/settings_get_str settings_set_str signal_emit signal_add_last/;
our $VERSION = "0.1";
our %IRSSI = (
authors => 'Urchlay',
contact => 'Urchlay on NewNet',
name => 'help_path_completion',
description => 'Support /help word completion for files in help_path',
license => 'Same as Perl',
url => 'none',
);
sub complete_word {
my ($complist, $window, $word, $linestart, $want_space) = @_;
return unless $linestart =~ m{/help}i;
for(split /:/, settings_get_str('help_path')) {
opendir my $dir, $_ or next;
push @$complist, grep { $_ !~ /\./ && $_ =~ /$word/i } readdir($dir);
closedir $dir;
}
}
# Add per-user help dir to help_path, if not already present.
sub init_help_path {
my $dir = "$ENV{HOME}/.irssi/help";
my $help_path = settings_get_str('help_path');
return if grep { $_ eq $dir } split /:/, $help_path;
$help_path .= ":$dir";
settings_set_str('help_path', $help_path);
signal_emit('setup changed');
}
init_help_path();
signal_add_last("complete word", \&complete_word);
|