使用comp_*
样式处理程序,人们只能匹配一个完成对最后一个不完整的单词。幸运的是,您可以通过覆盖下面的catch_comp函数来获得所需的结果;它可以让抗全命令行一场比赛:
my %completion_tree = (
stack => { under => [],
over => [qw(flow sample junk)] }
);
sub catch_comp {
my $o = shift;
my ($cmd, $word, $line, $start) = @_;
my $completed = substr $line, 0, $start;
$completed =~ s/^\s*//;
my $tree = \%completion_tree;
foreach (split m'\s+', $completed) {
last if ref($tree) ne 'HASH';
$tree = $tree->{$_};
}
my @completions;
$_ = ref($tree);
@completions = @$tree if /ARRAY/;
@completions = keys %$tree if /HASH/;
@completions = ($tree)if /SCALAR/;
return $o->completions($word, [@completions]);
}
好吧,现在我已经看了Term :: Shell,我注意到你需要写'sub comp_stack`。我错了吗?你的`comp_stack`中有什么? – 2009-07-24 13:13:26