[LDAPsh-cvs] ldapsh ldapsh,1.31,1.32
Status: Beta
Brought to you by:
rcorvalan
From: <j-d...@us...> - 2003-12-11 12:41:11
|
Update of /cvsroot/ldapsh/ldapsh In directory sc8-pr-cvs1:/tmp/cvs-serv23154 Modified Files: ldapsh Log Message: * Added the "-" and two-argument syntaxes for "cd" (like real shells). Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** ldapsh 6 Nov 2003 04:14:20 -0000 1.31 --- ldapsh 11 Dec 2003 12:41:07 -0000 1.32 *************** *** 243,246 **** --- 243,247 ---- my $Globals = { CWD => {VALUE => '', RIGHTS => 'RWL'}, + OLDWD => {VALUE => '', RIGHTS => 'RWL'}, CONNPARAMS => {VALUE => { *************** *** 282,286 **** }; ! my ($CWD, $PROMPT, $CONNPARAMS, $LDAPCONN, $ENTRIES, $EDITOR, $COLUMNS, $DNSEP, $G); my ($PERL_RL); # read-only values my ($Term, $TermAttribs); --- 283,287 ---- }; ! my ($CWD, $OLDWD, $PROMPT, $CONNPARAMS, $LDAPCONN, $ENTRIES, $EDITOR, $COLUMNS, $DNSEP, $G); my ($PERL_RL); # read-only values my ($Term, $TermAttribs); *************** *** 1282,1290 **** =head3 cd ! B<Synopsis>: C<cd ['E<lt>RDNE<gt>']> ! Change the I<current working directory> to the specified RDN. You can specify multiple RDNs separated by commas (in the reverse order of the DN, to allow completion). You can also specify ".." to go to the parent DN. If no RDN is specified, the I<current working directory> is not changed. See also the L<acd|acd>, L<setdn|setdn>, L<pushd|pushd> and L<popd|popd> commands. --- 1283,1300 ---- =head3 cd ! B<Synopsis>: C<cd ['E<lt>RDNE<gt>' | 'E<lt>fooE<gt>', 'E<lt>barE<gt>' | '-']> ! Change the I<current working directory> to the specified RDN. ! You can specify multiple RDNs separated by commas (in the reverse order of the DN, to allow completion). ! You can also specify C<..> to go to the parent DN. If no RDN is specified, the I<current working directory> is not changed. + If C<-> is specified, L<$OLDWD|$OLDWD> is swapped with the I<current working directory>. + + If C<foo> and C<bar> are specified, C<bar> will be substituted for C<foo> + in the I<current working directory> and the result will be used to + invoke L<setdn|setdn>. If C<foo> was not present in L<$CWD|$CWD>, + the I<current working directory> is not changed. + See also the L<acd|acd>, L<setdn|setdn>, L<pushd|pushd> and L<popd|popd> commands. *************** *** 1294,1299 **** --- 1304,1336 ---- _bindneeded() or return 0; + if (scalar @_ > 1) { + if (scalar @_ != 2) { + print STDERR "You may not specify more than two RDNs.\n"; + return 0; + } + my $pre = shift; + my $post = shift; + # if you know a better way of doing this, let us know! + my $i = index($Globals->{CWD}{VALUE}, $pre); + if ($i < 0) { + print STDERR "Substitution failed.\n"; + return 0; + } + my $NewPATH = substr($Globals->{CWD}{VALUE}, $i + length($pre)); + if (!defined($NewPATH)) { + print STDERR "Substitution failed.\n"; + return 0; + } + $NewPATH = substr($Globals->{CWD}{VALUE}, 0, $i).$post.$NewPATH; + return setdn($NewPATH); + } + my $SubPath = shift(); $SubPath = "" unless defined($SubPath); + + if ($SubPath eq "-") { + return setdn($Globals->{OLDWD}{VALUE}); + } + $SubPath =~ s/\s*,\s*$//; $SubPath = join(',', reverse(split(/\s*,\s*/, $SubPath))); *************** *** 1329,1332 **** --- 1366,1370 ---- sub setdn { my $NewPATH = shift; + my $OldPATH = $Globals->{CWD}{VALUE}; my $result = _searchWEC( *************** *** 1350,1353 **** --- 1388,1392 ---- if (scalar(@entries) == 1) { $Globals->{CWD}{VALUE} = $NewPATH; + $Globals->{OLDWD}{VALUE} = $OldPATH; return 1; } else { *************** *** 1374,1378 **** =head3 pushd ! B<Synopsis>: C<pushd ['E<lt>RDNE<gt>']> Perform the same action as the L<cd|cd> command. If the action succeeds, the old working directory is stored on a stack (which can be shown using L<dirs|dirs>). It can be restored using L<popd|popd>. --- 1413,1417 ---- =head3 pushd ! B<Synopsis>: C<pushd ['E<lt>RDNE<gt>' | 'E<lt>fooE<gt>', 'E<lt>barE<gt>' | '-']> Perform the same action as the L<cd|cd> command. If the action succeeds, the old working directory is stored on a stack (which can be shown using L<dirs|dirs>). It can be restored using L<popd|popd>. *************** *** 2438,2441 **** --- 2477,2484 ---- Contains the B<Net::LDAP> handler. Use it only if you know what you are doing... + + =head2 $OLDWD + + The immediate past I<current working directory>, updated by the L<cd|cd> and L<setdn|setdn> commands. =head2 $PROMPT |