App-Multigit
view release on metacpan or search on metacpan
script/mg-env view on Meta::CPAN
#!perl
use strict;
use warnings;
use 5.014;
use Getopt::Long qw(:config gnu_getopt passthrough);
use App::Multigit::Script;
use App::Multigit qw(mg_each);
use Path::Class;
use Future;
$options{absolute} = 1;
$options{'path-dir'} = [];
$options{reset} = 1;
GetOptions(
\%options,
'absolute!',
'path!',
'path-dir=s@',
'reset!',
'reset-only!',
);
push @{$options{'path-dir'} }, qw(bin script);
$ENV{MG_ENV_ORIGINAL_PERL5LIB} //= $ENV{PERL5LIB} || '';
$ENV{MG_ENV_ORIGINAL_PATH} //= $ENV{PATH} || '';
if ($options{reset}) {
say "PATH=$ENV{MG_ENV_ORIGINAL_PATH}; export PATH;";
say "PERL5LIB=$ENV{MG_ENV_ORIGINAL_PERL5LIB}; export PERL5LIB;";
say "unset MG_ENV_ORIGINAL_PATH; unset MG_ENV_ORIGINAL_PERL5LIB;";
exit if $options{'reset-only'};
}
my $future = mg_each(\&add_environment);
say "$_=$ENV{$_}; export $_;"
for qw/ MG_ENV_ORIGINAL_PATH MG_ENV_ORIGINAL_PERL5LIB/;
say for $future->get;
sub add_environment {
my ($repo) = @_;
my $dir = $repo->config->{dir};
if ($options{absolute}) {
$dir = dir($dir)->absolute;
}
my @env;
if (-d (my $perl5dir = dir($dir, 'lib'))) {
@env = qq(PERL5LIB="$perl5dir:\$PERL5LIB"; export PERL5LIB;);
}
if ($options{path}) {
for (@{$options{'path-dir'}}) {
if (-d (my $pathdir = dir($dir, $_))) {
push @env, qq(PATH="$pathdir:\$PATH; export PATH;);
}
}
}
Future->done(@env);
}
# PODNAME: mg-env
=head1 SYNOPSIS
mg env [ --path[=dir][, ...] ] [ --[no-]absolute ]
eval $(mg env)
=head1 DESCRIPTION
Outputs a bash-compatible script that sets environment variables,
specifically PERL5LIB.
=head1 OPTIONS
=over
=item --absolute
=item --no-absolute
Output absolute directories, which is the default. The alternative is
relative to the mg root.
=item --path
Also output PATH. By default, directories C<bin> and C<script> are
considered to contain things that make sense to PATH. Use L</--path-dir> to
change it.
=item --path-dir=dir
Add values to the paths considered for PATH.
mg env --path --path-dir=scripts
( run in 0.453 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )