Added -e (--export) and -p (--private) options.

This commit is contained in:
hjp 2011-10-07 08:03:22 +00:00
parent 1419d9dbc3
commit c5acc52b65
3 changed files with 69 additions and 8 deletions

View File

@ -28,6 +28,16 @@ Use the environment variable I<variable> instead of PATH.
This is useful for manipulating other PATH-like variables, like This is useful for manipulating other PATH-like variables, like
LD_LIBRARY_PATH, PERL5LIB, etc. LD_LIBRARY_PATH, PERL5LIB, etc.
=item B<-e>
Print a complete export statement ready to be eval'd by a POSIX shell.
=item B<-p>
Print a complete variable assignment statement ready to be eval'd by a
POSIX shell. Unlike the C<-e> option this does not prepend the export
keyword, so the variable is private unless it is exported elsewhere.
=back =back
=head1 AUTHOR =head1 AUTHOR
@ -42,9 +52,13 @@ use Getopt::Long;
my $check; my $check;
my $debug; my $debug;
my $var = 'PATH'; my $var = 'PATH';
GetOptions("check" => \$check, my $export;
"debug" => \$debug, my $private;
"var=s" => \$var, GetOptions("check" => \$check,
"debug" => \$debug,
"var=s" => \$var,
"export" => \$export,
"private" => \$private,
) or do { ) or do {
require Pod::Usage; require Pod::Usage;
import Pod::Usage; import Pod::Usage;
@ -64,4 +78,10 @@ nd: for my $nd (@ARGV) {
} }
push @path, $nd if (!$check || -d $nd); push @path, $nd if (!$check || -d $nd);
} }
if ($export) {
print "export ";
}
if ($export || $private) {
print "$var=";
}
print join(':', @path), "\n"; print join(':', @path), "\n";

View File

@ -23,6 +23,16 @@ Use the environment variable I<variable> instead of PATH.
This is useful for manipulating other PATH-like variables, like This is useful for manipulating other PATH-like variables, like
LD_LIBRARY_PATH, PERL5LIB, etc. LD_LIBRARY_PATH, PERL5LIB, etc.
=item B<-e>
Print a complete export statement ready to be eval'd by a POSIX shell.
=item B<-p>
Print a complete variable assignment statement ready to be eval'd by a
POSIX shell. Unlike the C<-e> option this does not prepend the export
keyword, so the variable is private unless it is exported elsewhere.
=back =back
=head1 AUTHOR =head1 AUTHOR
@ -37,8 +47,12 @@ use Pod::Usage;
my $debug; my $debug;
my $var = 'PATH'; my $var = 'PATH';
GetOptions("debug" => \$debug, my $export;
"var=s" => \$var, my $private;
GetOptions("debug" => \$debug,
"var=s" => \$var,
"export" => \$export,
"private" => \$private,
) or pod2usage(2); ) or pod2usage(2);
if ($#ARGV == 0 && $ARGV[0] =~ /:/) { if ($#ARGV == 0 && $ARGV[0] =~ /:/) {
@ -55,4 +69,10 @@ for (@del{@ARGV}) {
@path = grep { !$del{$_} } @path; @path = grep { !$del{$_} } @path;
if ($export) {
print "export ";
}
if ($export || $private) {
print "$var=";
}
print join(':', @path), "\n"; print join(':', @path), "\n";

View File

@ -28,6 +28,16 @@ Use the environment variable I<variable> instead of PATH.
This is useful for manipulating other PATH-like variables, like This is useful for manipulating other PATH-like variables, like
LD_LIBRARY_PATH, PERL5LIB, etc. LD_LIBRARY_PATH, PERL5LIB, etc.
=item B<-e>
Print a complete export statement ready to be eval'd by a POSIX shell.
=item B<-p>
Print a complete variable assignment statement ready to be eval'd by a
POSIX shell. Unlike the C<-e> option this does not prepend the export
keyword, so the variable is private unless it is exported elsewhere.
=back =back
=head1 AUTHOR =head1 AUTHOR
@ -42,9 +52,13 @@ use Getopt::Long;
my $check; my $check;
my $debug; my $debug;
my $var = 'PATH'; my $var = 'PATH';
GetOptions("check" => \$check, my $export;
"debug" => \$debug, my $private;
"var=s" => \$var, GetOptions("check" => \$check,
"debug" => \$debug,
"var=s" => \$var,
"export" => \$export,
"private" => \$private,
) or do { ) or do {
require Pod::Usage; require Pod::Usage;
import Pod::Usage; import Pod::Usage;
@ -67,4 +81,11 @@ for my $d (@ARGV, @path) {
$seen{$d} = 1; $seen{$d} = 1;
} }
} }
if ($export) {
print "export ";
}
if ($export || $private) {
print "$var=";
}
print join(':', @newpath), "\n"; print join(':', @newpath), "\n";