summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-11 15:38:08 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-11 15:38:08 +0200
commit43d91ad12990f3d132df99c636f61d9a7918ea0f (patch)
tree39bdd9a4dfa4b2f1971edb1d77e7fd97b3cca81a
parentNew script to convert file names to UNIX (WIP) (diff)
downloaddotfiles-bsd-43d91ad12990f3d132df99c636f61d9a7918ea0f.tar.gz
dotfiles-bsd-43d91ad12990f3d132df99c636f61d9a7918ea0f.tar.bz2
dotfiles-bsd-43d91ad12990f3d132df99c636f61d9a7918ea0f.tar.xz
dotfiles-bsd-43d91ad12990f3d132df99c636f61d9a7918ea0f.tar.zst
dotfiles-bsd-43d91ad12990f3d132df99c636f61d9a7918ea0f.zip
unixize script done
-rwxr-xr-x.local/bin/unixize29
1 files changed, 20 insertions, 9 deletions
diff --git a/.local/bin/unixize b/.local/bin/unixize
index b9ae293..74423d0 100755
--- a/.local/bin/unixize
+++ b/.local/bin/unixize
@@ -2,17 +2,16 @@
use warnings;
use strict;
-use File::Copy;
+use File::Copy qw/mv/;
sub get_og_files
{
my @og_files;
- my $file;
opendir(DIR, '.') or die $!;
- while ($file = readdir(DIR)) {
- next if ($file =~ m/^\./);
- push @og_files, $file;
+ while (readdir(DIR)) {
+ next if ($_ =~ m/^\./);
+ push @og_files, $_;
}
closedir(DIR);
return @og_files;
@@ -23,8 +22,10 @@ sub get_new_files
my @og_files = @_;
my @new_files;
- push @new_files, @og_files;
- foreach (@new_files) {
+ foreach (@og_files) {
+ $_ =~ s/\ /_/g;
+ $_ = lc($_);
+ push @new_files, $_;
}
return @new_files;
}
@@ -33,11 +34,21 @@ sub main
{
my @og_files;
my @new_files;
+ my @files;
@og_files = get_og_files();
@new_files = get_new_files(@og_files);
- foreach (@new_files) {
- print "'$_'\n";
+ while (@og_files || @new_files) {
+ $files[0] = shift @og_files;
+ $files[1] = shift @new_files;
+ if (@ARGV == 1 && $ARGV[0] eq '-R' && -d $files[0]) {
+ chdir($files[0]) or die $!;
+ main();
+ chdir('../');
+ }
+ next if (-e $files[1]);
+ mv($files[0], $files[1]) or print STDERR $! . "\n";
+ print "'". $files[0] . "' -> '" . $files[1] . "'\n";
}
return;
}