Fix autocompleter for all commands.
FossilOrigin-Name: 7ed32fefcd1fa2274fc7a6d55caf567a7875c8dac630fbcd260ceea37025bdf1
This commit is contained in:
parent
c08875fa11
commit
5dc5417902
1 changed files with 43 additions and 36 deletions
79
shelldap
79
shelldap
|
|
@ -1284,39 +1284,43 @@ sub debug
|
||||||
|
|
||||||
### Autocomplete values: Returns cached children entries.
|
### Autocomplete values: Returns cached children entries.
|
||||||
###
|
###
|
||||||
sub comp_cwd
|
sub autocomplete_from_cwd
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return @{ $self->{'cwd_entries'} };
|
my $word = quotemeta shift;
|
||||||
|
return grep {/^$word/} @{ $self->{'cwd_entries'} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
### Autocomplete values: Returns previously set shelldap environment values.
|
### Autocomplete values: Returns previously set shelldap environment values.
|
||||||
###
|
###
|
||||||
sub comp_setenv
|
sub autocomplete_from_env
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return @{ $self->{'env'} };
|
my $word = quotemeta shift;
|
||||||
|
return grep {/^$word/} @{ $self->{'env'} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
### Autocomplete values: Returns all objectClasses as defined
|
### Autocomplete values: Returns all objectClasses as defined
|
||||||
### by the LDAP server.
|
### by the LDAP server.
|
||||||
###
|
###
|
||||||
sub comp_create
|
sub autocomplete_from_objectclasses
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return @{ $self->{'objectclasses'} };
|
my $word = quotemeta shift;
|
||||||
|
return grep {/^$word/} @{ $self->{'objectclasses'} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
### Autocomplete values: Returns all objectClasses as defined
|
### Autocomplete values: Returns all objectClasses as defined
|
||||||
### by the LDAP server, along with current children DNs.
|
### by the LDAP server, along with current children DNs.
|
||||||
###
|
###
|
||||||
sub comp_inspect
|
sub autocomplete_from_objectclasses_and_cwd
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return ('_schema', @{ $self->{'objectclasses'} }, @{ $self->{'cwd_entries'} });
|
my $word = quotemeta shift;
|
||||||
|
return grep {/^$word/} ('_schema', @{ $self->{'objectclasses'} }, @{ $self->{'cwd_entries'} });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1458,36 +1462,38 @@ sub diff {
|
||||||
# do so to assign autocompleter function to them, and/or to define aliases.
|
# do so to assign autocompleter function to them, and/or to define aliases.
|
||||||
tie my %cmd_map, 'Tie::IxHash';
|
tie my %cmd_map, 'Tie::IxHash';
|
||||||
%cmd_map = (
|
%cmd_map = (
|
||||||
|
# Real commands:
|
||||||
'whoami' => [ undef ],
|
'whoami' => [ undef ],
|
||||||
'pwd' => [ undef ],
|
'pwd' => [ undef ],
|
||||||
'list' => [ undef, 'comp_cwd' ],
|
'list' => [ undef, 'autocomplete_from_cwd' ],
|
||||||
'grep' => [ undef, 'comp_cwd' ],
|
'grep' => [ undef, 'autocomplete_from_cwd' ],
|
||||||
'edit' => [ undef, 'comp_cwd' ],
|
'edit' => [ undef, 'autocomplete_from_cwd' ],
|
||||||
'delete' => [ undef, 'comp_cwd' ],
|
'delete' => [ undef, 'autocomplete_from_cwd' ],
|
||||||
'copy' => [ undef, 'comp_cwd' ],
|
'copy' => [ undef, 'autocomplete_from_cwd' ],
|
||||||
'cat' => [ undef, 'comp_cwd' ],
|
'cat' => [ undef, 'autocomplete_from_cwd' ],
|
||||||
'move' => [ undef, 'comp_cwd' ],
|
'move' => [ undef, 'autocomplete_from_cwd' ],
|
||||||
'less' => [ undef, 'comp_cwd' ],
|
'less' => [ undef, 'autocomplete_from_cwd' ],
|
||||||
'cd' => [ undef, 'comp_cwd' ],
|
'cd' => [ undef, 'autocomplete_from_cwd' ],
|
||||||
'create' => [ undef, 'comp_create' ],
|
'create' => [ undef, 'autocomplete_from_objectclasses' ],
|
||||||
'setenv' => [ undef, 'comp_setenv' ],
|
'setenv' => [ undef, 'autocomplete_from_env' ],
|
||||||
'passwd' => [ undef ],
|
'passwd' => [ undef ],
|
||||||
'clear' => [ undef ],
|
'clear' => [ undef ],
|
||||||
'env' => [ undef ],
|
'env' => [ undef, 'autocomplete_from_env' ],
|
||||||
#'help' => [ undef ],
|
#'help' => [ undef ],
|
||||||
'mkdir' => [ undef ],
|
'mkdir' => [ undef ],
|
||||||
'inspect' => [ undef, 'comp_inspect' ],
|
'inspect' => [ undef, 'autocomplete_from_objectclasses_and_cwd' ],
|
||||||
|
|
||||||
|
# Aliases:
|
||||||
'id' => [ 'whoami' ],
|
'id' => [ 'whoami' ],
|
||||||
'ls' => [ 'list', 'comp_cwd' ],
|
'ls' => [ 'list' ],
|
||||||
'search' => [ 'grep', 'comp_cwd' ],
|
'search' => [ 'grep' ],
|
||||||
'vi' => [ 'edit', 'comp_cwd' ],
|
'vi' => [ 'edit' ],
|
||||||
'rm' => [ 'delete', 'comp_cwd' ],
|
'rm' => [ 'delete'],
|
||||||
'cp' => [ 'copy', 'comp_cwd' ],
|
'cp' => [ 'copy' ],
|
||||||
'read' => [ 'read', 'comp_cwd' ],
|
'read' => [ 'read' ],
|
||||||
'mv' => [ 'move', 'comp_cwd' ],
|
'mv' => [ 'move' ],
|
||||||
'touch' => [ 'create', 'comp_create' ],
|
'touch' => [ 'create' ],
|
||||||
'export' => [ 'setenv', 'comp_setenv' ],
|
'export' => [ 'setenv'],
|
||||||
'?' => [ 'help' ],
|
'?' => [ 'help' ],
|
||||||
'man' => [ 'help' ],
|
'man' => [ 'help' ],
|
||||||
);
|
);
|
||||||
|
|
@ -2408,17 +2414,18 @@ sub run_inspect
|
||||||
my %aliases;
|
my %aliases;
|
||||||
|
|
||||||
while(my($cmd, $data) = each %cmd_map ) {
|
while(my($cmd, $data) = each %cmd_map ) {
|
||||||
# If command is an alias, insert alias symbol.
|
# If command is an alias, it is enough to mark it as such.
|
||||||
if( $$data[0]) {
|
if( $$data[0]) {
|
||||||
$aliases{$$data[0]} ||= [];
|
$aliases{$$data[0]} ||= [];
|
||||||
push @{$aliases{$$data[0]}}, $cmd;
|
push @{$aliases{$$data[0]}}, $cmd;
|
||||||
|
|
||||||
|
# If it is a real command, let's do more work.
|
||||||
} else {
|
} else {
|
||||||
## If completer is defined, set it.
|
# If completer is defined, set it.
|
||||||
#if( $$data[1]) {
|
if( $$data[1]) {
|
||||||
# my $comp_sub = "comp_$cmd";
|
my $comp_sub = "comp_$cmd";
|
||||||
# *$comp_sub = \&{$$data[1]}
|
*$comp_sub = \&{$$data[1]}
|
||||||
#}
|
}
|
||||||
|
|
||||||
# Define help and summary functions for the command:
|
# Define help and summary functions for the command:
|
||||||
my $pod = ''; open my $io, '>', \$pod;
|
my $pod = ''; open my $io, '>', \$pod;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue