From c5acc52b657cf6f99da83f0dfa3705fea8d2d779 Mon Sep 17 00:00:00 2001 From: hjp Date: Fri, 7 Oct 2011 08:03:22 +0000 Subject: [PATCH] Added -e (--export) and -p (--private) options. --- pathtools/apppath.pl | 26 +++++++++++++++++++++++--- pathtools/delpath.pl | 24 ++++++++++++++++++++++-- pathtools/preppath.pl | 27 ++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/pathtools/apppath.pl b/pathtools/apppath.pl index c51a85b..2793497 100755 --- a/pathtools/apppath.pl +++ b/pathtools/apppath.pl @@ -28,6 +28,16 @@ Use the environment variable I instead of PATH. This is useful for manipulating other PATH-like variables, like 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 =head1 AUTHOR @@ -42,9 +52,13 @@ use Getopt::Long; my $check; my $debug; my $var = 'PATH'; -GetOptions("check" => \$check, - "debug" => \$debug, - "var=s" => \$var, +my $export; +my $private; +GetOptions("check" => \$check, + "debug" => \$debug, + "var=s" => \$var, + "export" => \$export, + "private" => \$private, ) or do { require Pod::Usage; import Pod::Usage; @@ -64,4 +78,10 @@ nd: for my $nd (@ARGV) { } push @path, $nd if (!$check || -d $nd); } +if ($export) { + print "export "; +} +if ($export || $private) { + print "$var="; +} print join(':', @path), "\n"; diff --git a/pathtools/delpath.pl b/pathtools/delpath.pl index 34967a4..d952969 100755 --- a/pathtools/delpath.pl +++ b/pathtools/delpath.pl @@ -23,6 +23,16 @@ Use the environment variable I instead of PATH. This is useful for manipulating other PATH-like variables, like 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 =head1 AUTHOR @@ -37,8 +47,12 @@ use Pod::Usage; my $debug; my $var = 'PATH'; -GetOptions("debug" => \$debug, - "var=s" => \$var, +my $export; +my $private; +GetOptions("debug" => \$debug, + "var=s" => \$var, + "export" => \$export, + "private" => \$private, ) or pod2usage(2); if ($#ARGV == 0 && $ARGV[0] =~ /:/) { @@ -55,4 +69,10 @@ for (@del{@ARGV}) { @path = grep { !$del{$_} } @path; +if ($export) { + print "export "; +} +if ($export || $private) { + print "$var="; +} print join(':', @path), "\n"; diff --git a/pathtools/preppath.pl b/pathtools/preppath.pl index 4884fc5..a096cf8 100755 --- a/pathtools/preppath.pl +++ b/pathtools/preppath.pl @@ -28,6 +28,16 @@ Use the environment variable I instead of PATH. This is useful for manipulating other PATH-like variables, like 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 =head1 AUTHOR @@ -42,9 +52,13 @@ use Getopt::Long; my $check; my $debug; my $var = 'PATH'; -GetOptions("check" => \$check, - "debug" => \$debug, - "var=s" => \$var, +my $export; +my $private; +GetOptions("check" => \$check, + "debug" => \$debug, + "var=s" => \$var, + "export" => \$export, + "private" => \$private, ) or do { require Pod::Usage; import Pod::Usage; @@ -67,4 +81,11 @@ for my $d (@ARGV, @path) { $seen{$d} = 1; } } + +if ($export) { + print "export "; +} +if ($export || $private) { + print "$var="; +} print join(':', @newpath), "\n";