2003-12-18 17:31:40 +01:00
|
|
|
#!@@@perl@@@ -w
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
apppath - append directories to path
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2007-01-04 18:00:45 +01:00
|
|
|
apppath [-c] [-v variable] directory...
|
2003-12-18 17:31:40 +01:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
apppath appends the directories given as arguments to the PATH and
|
|
|
|
prints the new path on stdout.
|
|
|
|
|
|
|
|
=head1 OPTIONS
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item B<-c>
|
|
|
|
|
|
|
|
Check whether the directories exist before adding them. Nonexistent
|
|
|
|
directories are silently ignored.
|
|
|
|
|
2007-01-04 18:00:45 +01:00
|
|
|
=item B<-v> I<variable>
|
|
|
|
|
|
|
|
Use the environment variable I<variable> instead of PATH.
|
|
|
|
This is useful for manipulating other PATH-like variables, like
|
|
|
|
LD_LIBRARY_PATH, PERL5LIB, etc.
|
|
|
|
|
2003-12-18 17:31:40 +01:00
|
|
|
=back
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Peter J. Holzer <hjp@hjp.at>.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
use strict;
|
2007-01-04 18:00:45 +01:00
|
|
|
use Getopt::Long;
|
2003-12-18 17:31:40 +01:00
|
|
|
|
2007-01-04 18:00:45 +01:00
|
|
|
my $check;
|
|
|
|
my $debug;
|
|
|
|
my $var = 'PATH';
|
|
|
|
GetOptions("check" => \$check,
|
|
|
|
"debug" => \$debug,
|
|
|
|
"var=s" => \$var,
|
2007-03-05 19:18:15 +01:00
|
|
|
) or do {
|
|
|
|
require Pod::Usage;
|
|
|
|
import Pod::Usage;
|
|
|
|
pod2usage(2);
|
|
|
|
};
|
2007-01-04 18:00:45 +01:00
|
|
|
|
|
|
|
my $path = $ENV{$var} || '';
|
|
|
|
my @path = split(/:/, $path);
|
2003-12-18 17:31:40 +01:00
|
|
|
|
|
|
|
if ($#ARGV == 0 && $ARGV[0] =~ /:/) {
|
|
|
|
@ARGV = split(/:/, $ARGV[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
nd: for my $nd (@ARGV) {
|
|
|
|
for my $od (@path) {
|
|
|
|
next nd if ($nd eq $od);
|
|
|
|
}
|
|
|
|
push @path, $nd if (!$check || -d $nd);
|
|
|
|
}
|
|
|
|
print join(':', @path), "\n";
|