使用以下代码:
#!/usr/bin/env perl
use warnings;
use strict;
package Testsh;
use base qw(Term::Shell);
my @actions = qw/ a b c d e f g h /;
sub comp_cd {
my ( $self, $action ) = @_;
$self->completions( $action, @actions);
}
sub run_cd {
my ( $self, $action ) = @_;
$self->prompt( "$action~> ");
}
package main;
my $shell = Testsh->new;
$shell->cmdloop;
当我启动 shell 并按 tab 两次时,我得到三个选项:cd、退出帮助。
如果我cd到其中一个操作,则提示将更改为操作名称,但我不再能够使用选项卡完成。这是为什么呢?
如 Term:Shell API 中所述,您可以将要prompt
的完成指定为第三个参数:
$self->prompt( "$action~> ", '', [ glob '*' ]);