Add a 'less' command, that does the same as cat, but uses a pager.
To avoid code duplication, refactor run_cat to be a thin wrapper around a common function called by both run_cat and run_less. FossilOrigin-Name: 28a0cda242c8cc11dcb8e5de781b0e52308808799afc012cc33651990da43b4f
This commit is contained in:
parent
d6d0a5f8b0
commit
7cc910744f
1 changed files with 31 additions and 4 deletions
35
shelldap
35
shelldap
|
|
@ -239,6 +239,10 @@ add a list of attributes to display. Use '+' for server side attributes.
|
||||||
cat uid=mahlon,ou=People,dc=example,o=company
|
cat uid=mahlon,ou=People,dc=example,o=company
|
||||||
cat uid=mahlon + userPassword
|
cat uid=mahlon + userPassword
|
||||||
|
|
||||||
|
=item B< less>
|
||||||
|
|
||||||
|
Like cat, but uses the configured pager to display output.
|
||||||
|
|
||||||
=item B< cd>
|
=item B< cd>
|
||||||
|
|
||||||
Change directory. Translated to LDAP, this changes the current basedn.
|
Change directory. Translated to LDAP, this changes the current basedn.
|
||||||
|
|
@ -472,6 +476,7 @@ sub init
|
||||||
$self->{'API'}->{'match_uniq'} = 0;
|
$self->{'API'}->{'match_uniq'} = 0;
|
||||||
|
|
||||||
$self->{'editor'} = $conf->{'editor'} || $ENV{'EDITOR'} || 'vi';
|
$self->{'editor'} = $conf->{'editor'} || $ENV{'EDITOR'} || 'vi';
|
||||||
|
$self->{'pager'} = $conf->{'pager'} || $ENV{'PAGER'} || 'less';
|
||||||
$self->{'env'} = [ qw/ debug cacheage timeout / ];
|
$self->{'env'} = [ qw/ debug cacheage timeout / ];
|
||||||
|
|
||||||
# let autocomplete work with the '=' character
|
# let autocomplete work with the '=' character
|
||||||
|
|
@ -1113,6 +1118,7 @@ sub comp_inspect
|
||||||
copy => 'cp',
|
copy => 'cp',
|
||||||
cat => 'read',
|
cat => 'read',
|
||||||
move => 'mv',
|
move => 'mv',
|
||||||
|
less => undef,
|
||||||
cd => undef,
|
cd => undef,
|
||||||
passwd => undef
|
passwd => undef
|
||||||
);
|
);
|
||||||
|
|
@ -1196,6 +1202,24 @@ sub run_cat
|
||||||
my $dn = shift;
|
my $dn = shift;
|
||||||
my @attrs = (@_) ? @_ : ('*');
|
my @attrs = (@_) ? @_ : ('*');
|
||||||
|
|
||||||
|
display($self, $dn, \@attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub run_less
|
||||||
|
{
|
||||||
|
my $self = shift;
|
||||||
|
my $dn = shift;
|
||||||
|
my @attrs = (@_) ? @_ : ('*');
|
||||||
|
|
||||||
|
display($self, $dn, \@attrs, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub display{
|
||||||
|
my $self = shift;
|
||||||
|
my $dn = shift;
|
||||||
|
my @attrs = @{;shift};
|
||||||
|
my $use_pager = shift;
|
||||||
|
|
||||||
unless ( $dn ) {
|
unless ( $dn ) {
|
||||||
print "No dn provided.\n";
|
print "No dn provided.\n";
|
||||||
return;
|
return;
|
||||||
|
|
@ -1241,13 +1265,16 @@ sub run_cat
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# display to stdout
|
# display to stdout or pager
|
||||||
#
|
#
|
||||||
|
my $ldif = $self->ldif($use_pager);
|
||||||
foreach my $e ( @{ $s->{'entries'} } ) {
|
foreach my $e ( @{ $s->{'entries'} } ) {
|
||||||
$self->ldif->write_entry( $e );
|
$ldif->write_entry( $e );
|
||||||
print "\n";
|
|
||||||
}
|
}
|
||||||
|
if($use_pager) {
|
||||||
|
system( $self->{'pager'}, $self->{'ldif_fname'} );
|
||||||
|
unlink $self->{'ldif_fname'};
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue