【发布时间】:2015-07-15 15:35:35
【问题描述】:
如何禁用Term::ReadLine 的默认补全,或者更确切地说,让它在某些时候停止建议文件名补全?
例如,我需要用什么替换 return() 以禁止从第二个单词开始的默认补全?
这些都不起作用:
$attribs->{'filename_completion_function'}=undef;
$attribs->{'rl_inhibit_completion'}=1;
use Term::ReadLine;
my $term = new Term::ReadLine 'sample';
my $attribs = $term->Attribs;
$attribs->{attempted_completion_function} = \&sample_completion;
sub sample_completion {
my ( $text, $line, $start, $end ) = @_;
# If first word then username completion, else filename completion
if ( substr( $line, 0, $start ) =~ /^\s*$/ ) {
return $term->completion_matches( $text,
$attribs->{'username_completion_function'} );
}
else {
return ();
}
}
while ( my $input = $term->readline( "> " ) ) {
...
}
【问题讨论】:
-
试试
filename_completion_desired -
像这样:
$attribs->{filename_completion_desired}=0;?或者$attribs->{rl_filename_completion_desired}=0;?不工作。 -
我只是从文档中猜测。对于 Gnu 变体,所有变量名称都记录在 here 中。
$attribs哈希的键已删除前导rl_。您可能需要use Term::ReadLine::Gnu或将环境变量PERL_RL设置为Gnu才能正常工作。 -
谢谢。我们不允许直接
use Term::ReadLine::Gnu。通过反复试验,似乎要走的路是定义,不是attempted_completion_function,而是completion_function,然后是return $term->completion_matches($text, $attribs->{filename_completion_function}),只要默认文件名完成是接管。 -
干得好。你应该把它写下来作为答案并接受它。所有这些禁止人们使用模块的官僚作风都是奇怪的!
标签: perl tab-completion