#!/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);