A utility to mark and operate on files in the shell.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.1 KiB

#!/usr/bin/env perl
use warnings;
use strict;
use 5.10.0;
use App::MarkFiles qw(each_path check_collisions);
use File::Basename;
use File::Copy;
use File::Spec;
use Getopt::Long;
my $dry_run;
'no-action|dry-run|n' => \$dry_run,
help => sub { pod2usage(0) },
) or pod2usage(2);
my (@collisions) = check_collisions();
if (scalar @collisions) {
# We got something. Alert the user and bail.
say "Multiple marked paths would be copied to the following filenames:";
say join "\n", @collisions;
say "";
say "No action taken, since this probably isn't what you want.";
each_path(sub {
my ($path) = @_;
unless (-e $path) {
say "No such file: $path";
my ($source_basename, $source_path) = fileparse($path);
my $target = File::Spec->catfile('.', $source_basename);
if (-e $target) {
say "Warning: $path will overwrite $target";
# See marks-mv for some discussion of what happens if target exists.
if ($dry_run) {
say "Would copy: $path";
if (copy($path, './')) {
say "Copied: $path";
} else {
say "Copy failed: $!"