[LDAPsh-cvs] ldapsh ldapsh,1.28,1.29
Status: Beta
Brought to you by:
rcorvalan
From: <j-d...@us...> - 2003-11-06 03:36:07
|
Update of /cvsroot/ldapsh/ldapsh In directory sc8-pr-cvs1:/tmp/cvs-serv11989 Modified Files: ldapsh Log Message: PATCH-812862 (multi-column format for ls). Documentation for variables is now in alphabetical order. Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** ldapsh 6 Nov 2003 03:20:29 -0000 1.28 --- ldapsh 6 Nov 2003 03:36:02 -0000 1.29 *************** *** 253,257 **** --- 253,263 ---- }, LDAPCONN => {VALUE => undef, RIGHTS => 'RW'}, + DNSEP => {VALUE => "; ", RIGHTS => 'RWL'}, ENTRIES => {VALUE => [], RIGHTS => 'RW'}, + COLUMNS => {VALUE => + ( $ENV{COLUMNS} && $ENV{COLUMNS} =~ /^[+]?\d+$/ ) ? + $ENV{COLUMNS} : ( eval "require Term::Size; Term::Size::chars();" || 80 ), + RIGHTS => 'RWL' + }, PROMPT => {VALUE => '${APP}\[LDAP @ $CONNPARAMS->{SERVER}] $CWD > ', RIGHTS => 'RWL'}, EDITOR => {VALUE => $ENV{VISUAL} ? $ENV{VISUAL} : ($ENV{EDITOR} ? $ENV{EDITOR} : 'vi'), RIGHTS => 'RWL'}, *************** *** 276,280 **** }; ! my ($CWD, $PROMPT, $CONNPARAMS, $LDAPCONN, $ENTRIES, $EDITOR, $G); my ($Term, $TermAttribs); --- 282,286 ---- }; ! my ($CWD, $PROMPT, $CONNPARAMS, $LDAPCONN, $ENTRIES, $EDITOR, $COLUMNS, $DNSEP, $G); my ($Term, $TermAttribs); *************** *** 1682,1698 **** =head3 ls ! B<Synopsis>: C<ls ['-l',] E<lt>expansionE<gt>> ! List the DNs of the entries matched by the expansion (see L<Expansion|expansion>). The C<-r> parameter automatically sets the C<-l> parameter. =cut sub ls { ! my $localArgs = {}; ! my $entries = _entriesExpander [$localArgs, 'l'], @_; return 0 unless defined $entries; ! foreach my $entry (@$entries) { ! printf {$Output->{FILEHANDLE}} ("%s\n", $localArgs->{'l'} ? $entry->dn : rdn($entry->dn)); } print STDERR "-----\n" . scalar(@$entries) . " entries found.\n"; --- 1688,1754 ---- =head3 ls ! B<Synopsis>: C<ls ['-C',|'-m',] ['-l',] E<lt>expansionE<gt>> ! List the DNs of the entries matched by the expansion (see L<Expansion|expansion>). ! Entries are displayed in the order received (no sorting is performed), ! with one entry per line. ! ! The C<-C> argument requests multi-column output (the default is to print only one column per line). ! B<ldapsh> uses as many columns as will fit into the character width of the terminal (see L<$COLUMNS|"$COLUMNS">). ! If C<-m> is also specified, columns will be separated by L<$DNSEP|"$DNSEP"> (the default string is "; "). ! The separator is omitted from the last entry on each line. ! ! The C<-m> argument requests that all entries be printed on a single line, ! with entries separated by the L<$DNSEP|"$DNSEP"> string (the default string is "; "). ! The separator appears after every entry (including the last one). =cut sub ls { ! my $localArgs = {C => 0, m => 0}; ! my $entries = _entriesExpander [$localArgs, 'C', 'm', 'l'], @_; return 0 unless defined $entries; ! if ($localArgs->{'C'} && $Globals->{COLUMNS}{VALUE} > 0) { ! # determine the width of the longest entry ! my $i; ! my $num; ! my $width = 0; ! my @display = (); ! my $sep = $localArgs->{'m'} ? $Globals->{DNSEP}{VALUE} : " "; ! my $auxwidth = length($sep); ! foreach my $entry (@$entries) { ! unshift @display, $localArgs->{'l'} ? $entry->dn : rdn($entry->dn); ! $num = length($display[0]); ! if ($num > $width) { ! $width = $num; ! } ! } ! # $width is max width of any entry. ! # $num becomes the number of entries per line. ! $num = int(($Globals->{COLUMNS}{VALUE}+$auxwidth)/($width+$auxwidth)); ! ! $auxwidth += $width; ! for ($i = 0; @display; $i++) { ! if (@display == 1 || ($i+1) % $num == 0) { ! printf {$Output->{FILEHANDLE}} ("%-${width}s\n", shift @display); ! } ! else { ! printf {$Output->{FILEHANDLE}} ("%-${auxwidth}s", (shift @display).$sep); ! } ! } ! } ! elsif ($localArgs->{'m'}) { ! foreach my $entry (@$entries) { ! printf {$Output->{FILEHANDLE}} ("%s$Globals->{DNSEP}{VALUE}", $localArgs->{'l'} ? $entry->dn : rdn($entry->dn)); ! } ! if (@$entries) { ! printf "\n"; ! } ! } ! else { ! foreach my $entry (@$entries) { ! printf {$Output->{FILEHANDLE}} ("%s\n", $localArgs->{'l'} ? $entry->dn : rdn($entry->dn)); ! } } print STDERR "-----\n" . scalar(@$entries) . " entries found.\n"; *************** *** 2290,2296 **** =item * F</etc/ldapshrc> ! Same as F<~/.ldaprc>, only system-wide. ! =item * F<~/.ldapsh_history> For internal use. The shell saves the history in this file (provided you have --- 2346,2352 ---- =item * F</etc/ldapshrc> ! Same as F<$HOME/.ldaprc>, only system-wide. ! =item * F<$HOME/.ldapsh_history> For internal use. The shell saves the history in this file (provided you have *************** *** 2302,2305 **** --- 2358,2367 ---- =head1 VARIABLES + =head2 $COLUMNS + + The width of the output device in characters (decimal string). + Its initial value is obtained from the environment or the B<Term::Size> module, + with a default of 80 characters. + =head2 $CONNPARAMS-E<gt>{SERVER} *************** *** 2334,2353 **** using this variable). ! =head2 $LDAPCONN ! ! Contains the B<Net::LDAP> handler. Use it only if you know what you are doing... ! ! =head2 $ENTRIES ! ! The buffer of entries (B<Net::LDAP::Entry>). It's an array ref. Contains the last entries got with the ! commands L<ls|ls>, L<cat|cat>, L<search|search>... ! ! =head2 $PROMPT ! ! The prompt template. It will be "eval"ed so will do variable substitution. ! You can use the ${APP} variable to display "**" when you are in "append mode" ! (see L<append|append> and L<noappend|noappend>). ! Example: $PROMPT = '${APP}\[LDAP @ $CONNPARAMS-E<gt>{SERVER}] $CWD E<gt> ' =head2 $EDITOR --- 2396,2402 ---- using this variable). ! =head2 $DNSEP ! String used to separate DNs on a line (see L<ls|ls>). =head2 $EDITOR *************** *** 2356,2359 **** --- 2405,2413 ---- from the environment variable $VISUAL (if set) or $EDITOR (if set) or otherwise "vi". + =head2 $ENTRIES + + The buffer of entries (B<Net::LDAP::Entry>). It's an array ref. Contains the last entries got with the + commands L<ls|ls>, L<cat|cat>, L<search|search>... + =head2 $G *************** *** 2367,2370 **** --- 2421,2436 ---- B<Example>: C<$G = {ENTRIES => $ENTRIES, PWD => $PWD}; $G->{TIME} = time();> + + =head2 $LDAPCONN + + Contains the B<Net::LDAP> handler. Use it only if you know what you are doing... + + =head2 $PROMPT + + The prompt template. It will be "eval"ed so will do variable substitution. + You can use the ${APP} variable to display "**" when you are in "append mode" + (see L<append|append> and L<noappend|noappend>). + + Example: $PROMPT = '${APP}\[LDAP @ $CONNPARAMS-E<gt>{SERVER}] $CWD E<gt> ' =head1 SEE ALSO |