【发布时间】:2011-11-09 18:52:28
【问题描述】:
使用Term::ReadLine::Gnu 时,我似乎无法获得不区分大小写的完成。以这个示例脚本为例:
use strict;
use warnings;
use 5.010;
use Term::ReadLine;
my $term = Term::ReadLine->new('test');
say "Using " . $term->ReadLine;
if (my $attr = $term->Attribs) {
$term->ornaments(0);
$attr->{basic_word_break_characters} = ". \t\n";
$attr->{completer_word_break_characters} = " \t\n";
$attr->{completion_function} = \&complete_word;
} # end if attributes
my @words = qw(apple approve Adam America UPPER UPPERCASE UNUSED);
sub complete_word
{
my ($text, $line, $start) = @_;
return grep(/^$text/i, @words);
} # end complete_word
while (1) {
$_ = $term->readline(']');
last unless /\S/; # quit on empty input
} # end while 1
请注意,complete_word 进行不区分大小写的匹配。如果我用Term::ReadLine::Perl(通过PERL_RL=Perl perl script.pl)运行它,它会按我的预期工作。键入 a<TAB><TAB> 会列出所有 4 个单词。输入 u<TAB><TAB> 会将 u 转换为 U 并列出 3 个单词。
当我改用Term::ReadLine::Gnu(PERL_RL=Gnu perl script.pl 或只是perl script.pl)时,它只执行区分大小写的补全。输入 a<TAB> 会得到 app。键入 u<TAB><TAB> 不会列出任何完成。
我的/etc/inputrc 中什至有set completion-ignore-case on,但它在这里仍然不起作用。 (不过,它在 bash 中运行良好。)
有没有办法让Term::ReadLine::Gnu 进行不区分大小写的补全?
【问题讨论】:
标签: perl readline case-insensitive