diff options
Diffstat (limited to 'help_path_completion.pl')
-rw-r--r-- | help_path_completion.pl | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/help_path_completion.pl b/help_path_completion.pl new file mode 100644 index 0000000..8bb5e6a --- /dev/null +++ b/help_path_completion.pl @@ -0,0 +1,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); |