App-MiseEnPlace
view release on metacpan or search on metacpan
C<mise> is a simple script that allows you to manage directory and symlink
creation based on a global config as well as per-project configs.
=head1 OPTIONS
The config file in the SYNOPSIS illustrates most of the available options.
=over 4
=item bindir
The directory to be used for the expansion of the keyword 'BIN' when creating
symlinks. (See below.) Defaults to C<$ENV{HOME}/bin>
=item manage
This is a list of directories in which to search for per-project config
files. Directories that don't start with a '/' are assumed to be relative to
$ENV{HOME} (i.e., 'foo' will be expanded to "$ENV{HOME}/foo"). Each line will
be globbed, so standard shell wildcards can be used.
=item create/links
This is a list of symlinks to create, expressed as a series of source =>
target pairs. Both the source and target will be expanded relative to the
directory containing the C<.mise> file, as explained above for
create/directories. Additionally, if the target ends in a '/', the basename of
the source value will be appended (in much the same way the C<ln -s> works.)
Finally, there are a few keywords that can be used when creating links. If the
target consists solely of the keyword 'BIN', the link will be created in the
directory in the 'bindir' configuration variable, again using the basename of
the source. If the source consists solely of the keyword 'DIR', the link
source will be the directory containing the .mise file in question.
=back
=head1 FLAGS
=over 4
=item C<--config/-C FILE>
Use a different config file
=item C<--remove-bin-links/-R>
Makes C<mise> remove any sylinks from the C<bindir> after doing directory
creation and before doing symlink creation.
=item C<--verbose/-v>
Makes C<mise> be very noisy about exactly what is going on.
=item C<--version/-V>
Displays the version number and exits
lib/App/MiseEnPlace.pm view on Meta::CPAN
use File::HomeDir;
use Path::Tiny;
use Term::ANSIColor;
use Try::Tiny;
use Types::Standard -types;
use YAML qw/ LoadFile /;
use Moo;
use MooX::HandlesVia;
has bindir => (
is => 'rw' ,
isa => Str ,
lazy => 1 ,
default => sub { path( File::HomeDir->my_home , 'bin' )->stringify } ,
);
has config_file => (
is => 'rw' ,
isa => Str ,
lazy => 1 ,
lib/App/MiseEnPlace.pm view on Meta::CPAN
# also exit pager immediately if <1 page of output
$ENV{LESS} = 'RFX';
# don't catch any errors here; if this fails we just output stuff like
# normal and nobody is the wiser.
eval 'use IO::Page';
$self->_load_configs();
$self->_remove_bin_links($opt)
if $opt->{remove_bin_links} and -e -d $self->bindir();
$self->_create_dir( $_ ) for $self->all_directories();
$self->_create_link( $_ ) for $self->all_links();
}
sub _create_dir {
my( $self , $dir ) = @_;
my $msg;
lib/App/MiseEnPlace.pm view on Meta::CPAN
sub _parse_create_links {
my( $self, $link_array ) = @_;
my( %link_targets , @links );
for my $link_pair ( @$link_array ) {
my( $src , $target ) = ( %$link_pair );
my $src_base = path( $src )->basename();
$target = $self->bindir() if $target =~ m'BIN$';
$target = path($target, $src_base)->stringify()
if path($target)->is_dir() and ! path( $src )->is_dir();
if (exists $link_targets{$target} ) {
say "ERROR: Attempting to create multiple links to the same target:";
printf "%s -> %s\n%s -> %s\n" ,
$link_targets{$target} , $target , $src , $target;
}
$link_targets{$target} = $src;
lib/App/MiseEnPlace.pm view on Meta::CPAN
return path( $base )->stringify() if $base =~ m|^~|;
return path( $dir )->stringify( ) unless $base;
return path( $dir , $base )->stringify() unless $base =~ m|^/|;
return path( $base )->stringify();
}
sub _remove_bin_links {
my( $self , $opt ) = @_;
my $bin = $self->bindir();
opendir( my $dh , $bin );
while ( readdir $dh ) {
my $path = path( $bin , $_ );
next unless -l $path;
$path->remove();
say colored('UNLINK' , 'bright_red' ) , " ~/bin/$_"
( run in 0.484 second using v1.01-cache-2.11-cpan-2398b32b56e )