From 520a335ee68a1d3b0f7254e37e13c2a32387349e Mon Sep 17 00:00:00 2001 From: hjp Date: Thu, 4 Jan 2007 17:00:45 +0000 Subject: [PATCH] Added -v option. --- pathtools/apppath.pl | 27 +++++++++++++++++++-------- pathtools/delpath.pl | 24 ++++++++++++++++++++++-- pathtools/preppath.pl | 27 +++++++++++++++++++-------- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/pathtools/apppath.pl b/pathtools/apppath.pl index 261991d..325e682 100755 --- a/pathtools/apppath.pl +++ b/pathtools/apppath.pl @@ -6,7 +6,7 @@ apppath - append directories to path =head1 SYNOPSIS -apppath [-c] directory... +apppath [-c] [-v variable] directory... =head1 DESCRIPTION @@ -22,6 +22,12 @@ prints the new path on stdout. Check whether the directories exist before adding them. Nonexistent directories are silently ignored. +=item B<-v> I + +Use the environment variable I instead of PATH. +This is useful for manipulating other PATH-like variables, like +LD_LIBRARY_PATH, PERL5LIB, etc. + =back =head1 AUTHOR @@ -31,14 +37,19 @@ Peter J. Holzer . =cut use strict; -my $path = $ENV{PATH}; -my @path = split(/:/, $path); -my $check; +use Getopt::Long; +use Pod::Usage; -if ($ARGV[0] eq '-c') { - $check = 1; - shift; -} +my $check; +my $debug; +my $var = 'PATH'; +GetOptions("check" => \$check, + "debug" => \$debug, + "var=s" => \$var, + ) or pod2usage(2); + +my $path = $ENV{$var} || ''; +my @path = split(/:/, $path); if ($#ARGV == 0 && $ARGV[0] =~ /:/) { @ARGV = split(/:/, $ARGV[0]); diff --git a/pathtools/delpath.pl b/pathtools/delpath.pl index dc73ea2..34967a4 100755 --- a/pathtools/delpath.pl +++ b/pathtools/delpath.pl @@ -6,13 +6,25 @@ delpath - delete directories from path =head1 SYNOPSIS -delpath directory... +delpath [-v variable] directory... =head1 DESCRIPTION delpath deletes the directories given as arguments from the PATH and prints the new path on stdout. +=head1 OPTIONS + +=over 4 + +=item B<-v> I + +Use the environment variable I instead of PATH. +This is useful for manipulating other PATH-like variables, like +LD_LIBRARY_PATH, PERL5LIB, etc. + +=back + =head1 AUTHOR Peter J. Holzer . @@ -20,12 +32,20 @@ Peter J. Holzer . =cut use strict; +use Getopt::Long; +use Pod::Usage; + +my $debug; +my $var = 'PATH'; +GetOptions("debug" => \$debug, + "var=s" => \$var, + ) or pod2usage(2); if ($#ARGV == 0 && $ARGV[0] =~ /:/) { @ARGV = split(/:/, $ARGV[0]); } -my $path = $ENV{PATH}; +my $path = $ENV{$var}; my @path = split(/:/, $path); my %del; diff --git a/pathtools/preppath.pl b/pathtools/preppath.pl index b13c13b..38fb2a7 100755 --- a/pathtools/preppath.pl +++ b/pathtools/preppath.pl @@ -6,7 +6,7 @@ preppath - prepend directories to path =head1 SYNOPSIS -preppath [-c] directory... +preppath [-c] [-v variable] directory... =head1 DESCRIPTION @@ -22,6 +22,12 @@ eliminates any duplicates and prints the new path on stdout. Check whether the directories exist before adding them. Nonexistent directories are silently ignored. +=item B<-v> I + +Use the environment variable I instead of PATH. +This is useful for manipulating other PATH-like variables, like +LD_LIBRARY_PATH, PERL5LIB, etc. + =back =head1 AUTHOR @@ -31,14 +37,19 @@ Peter J. Holzer . =cut use strict; -my $path = $ENV{PATH}; -my @path = split(/:/, $path); -my $check; +use Getopt::Long; +use Pod::Usage; -if ($ARGV[0] eq '-c') { - $check = 1; - shift; -} +my $check; +my $debug; +my $var = 'PATH'; +GetOptions("check" => \$check, + "debug" => \$debug, + "var=s" => \$var, + ) or pod2usage(2); + +my $path = $ENV{$var} || ''; +my @path = split(/:/, $path); if ($#ARGV == 0 && $ARGV[0] =~ /:/) { @ARGV = split(/:/, $ARGV[0]);