[LDAPsh-cvs] ldapsh ldapsh,1.26,1.26.2.1
Status: Beta
Brought to you by:
rcorvalan
From: <j-d...@us...> - 2003-09-26 03:43:52
|
Update of /cvsroot/ldapsh/ldapsh In directory sc8-pr-cvs1:/tmp/cvs-serv5812 Modified Files: Tag: PATCH-812862 ldapsh Log Message: Provides -C and -m options for ls, removes some ls documentation that was incorrect. Adds $DNSEP and $COLUMNS, puts documentation of variables into alphabetical order. Untested. Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.26 retrieving revision 1.26.2.1 diff -C2 -d -r1.26 -r1.26.2.1 *** ldapsh 26 Sep 2003 03:29:58 -0000 1.26 --- ldapsh 26 Sep 2003 03:43:48 -0000 1.26.2.1 *************** *** 253,257 **** --- 253,263 ---- ENTRIES => {VALUE => [], RIGHTS => 'RW'}, PROMPT => {VALUE => '${APP}\[LDAP @ $CONNPARAMS->{SERVER}] $CWD > ', RIGHTS => 'RWL'}, + DNSEP => {VALUE => "; ", RIGHTS => 'RWL'}, EDITOR => {VALUE => $ENV{VISUAL} ? $ENV{VISUAL} : ($ENV{EDITOR} ? $ENV{EDITOR} : 'vi'), RIGHTS => 'RWL'}, + COLUMNS => {VALUE => + ( $ENV{COLUMNS} && $ENV{COLUMNS} =~ /^[+]?\d+$/ ) ? + $ENV{COLUMNS} : ( eval "require Term::Size; Term::Size::chars;" || 80 ), + RIGHTS => 'RWL' + }, G => {VALUE => undef, RIGHTS => 'RWL'}, _APPENDRESULTS => {VALUE => 0, RIGHTS => ''}, *************** *** 274,278 **** }; ! my ($CWD, $PROMPT, $CONNPARAMS, $LDAPCONN, $ENTRIES, $EDITOR, $G); my ($Term, $TermAttribs); --- 280,284 ---- }; ! my ($CWD, $PROMPT, $CONNPARAMS, $LDAPCONN, $ENTRIES, $EDITOR, $COLUMNS, $DNSEP, $G); my ($Term, $TermAttribs); *************** *** 1680,1696 **** =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"; --- 1686,1751 ---- =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). ! ! 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"; *************** *** 2262,2268 **** =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 --- 2317,2323 ---- =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 *************** *** 2274,2277 **** --- 2329,2338 ---- =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} *************** *** 2306,2325 **** 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 --- 2367,2373 ---- using this variable). ! =head2 $DNSEP ! String used to separate DNs on a line (see L<ls|ls>). =head2 $EDITOR *************** *** 2328,2331 **** --- 2376,2384 ---- 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 *************** *** 2339,2342 **** --- 2392,2407 ---- 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 |