-
-
Save vifon/3326648 to your computer and use it in GitHub Desktop.
mvln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
=head1 NAME | |
mvln - move a file and leave a symlink to its new location in its place | |
=head1 SYNOPSIS | |
B<mvln> I<source> I<destination> | |
B<mvln> I<sources...> I<destination_directory> | |
B<mvln> I<--help> | |
=head1 AUTHOR | |
Wojciech 'vifon' Siewierski <darkvifon at gmail dot com> | |
=head1 COPYRIGHT | |
Copyright (C) 2012 Wojciech Siewierski | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
=cut | |
use warnings; | |
use strict; | |
use File::Basename; | |
use File::Spec; | |
use File::Copy qw(mv); | |
use Pod::Usage; | |
unless (@ARGV == 0) { | |
pod2usage({ -verbose => 2 }) if $ARGV[0] eq "--help" | |
or $ARGV[0] eq "-h"; | |
} | |
pod2usage({ -verbose => 1 }) if @ARGV < 2; | |
my $destination = pop @ARGV; | |
if (@ARGV > 1 && not -d $destination) { | |
die "\"$destination\" is not a directory\n" | |
} | |
$destination = File::Spec->rel2abs($destination); | |
for my $file (@ARGV) { | |
my $destination_file; | |
if (-d $destination) { # get path to file created in the specified directory | |
$destination_file = File::Spec->catdir($destination, | |
basename($file)); | |
} else { | |
$destination_file = $destination; | |
} | |
mv $file, $destination_file; | |
symlink $destination_file, $file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment