Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add scriptlets: keep-one-ext, remove-all-ext, remove-ext

  • Loading branch information...
commit abe501083ca6cddadba8094207f99950b1d4dae2 1 parent 1d7666f
Steven Haryanto (on PC) authored
View
5 Changes
@@ -1,5 +1,10 @@
Revision history for App-perlmv
+0.42 NOT YET RELEASED
+
+ Add scriptlets: keep-one-ext, remove-ext, remove-all-ext.
+
+
0.41 2010-10-18
Add scriptlet: to-number & to-timestamp.
View
35 lib/App/perlmv/scriptlets/std.pm
@@ -19,6 +19,19 @@ $scriptlets{'dedup-space'} = <<'EOT';
s/\s{2,}/ /g; $_
EOT
+=head2 keep-one-ext
+
+Remove all but the last file extension if there are more than one, e.g. (1.tar,
+2.mp3.mp3) -> (1.tar, 2.mp3). TODO: treat tar.gz/tar.bz2/etc as one
+extension.
+
+=cut
+
+$scriptlets{'keep-one-ext'} = <<'EOT';
+### Summary: Remove all but the last file extension if there are more than one, e.g. (1.tar, 2.mp3.mp3) -> (1.tar, 2.mp3)
+s/(.+?)(?:\.\w{1,5})+(\.\w{1,5})$/$1$2/
+EOT
+
=head2 pinyin
Rename Chinese characters in filename into their pinyin. Requires
@@ -75,6 +88,28 @@ s/\Q$COMMON_SUFFIX\E$/$EXT/;
$_
EOT
+=head2 remove-ext
+
+Remove the last file extension, e.g. (1, 2.mp3, 3.tar.gz) -> (1, 2, 3.tar)
+
+=cut
+
+$scriptlets{'remove-ext'} = <<'EOT';
+### Summary: Remove the last file extension, e.g. (1, 2.mp3, 3.tar.gz) -> (1, 2, 3.tar)
+s/(.+)\.\w{1,5}$/$1/
+EOT
+
+=head2 remove-all-ext
+
+Remove all file extensions, e.g. (file.html.gz) -> (file)
+
+=cut
+
+$scriptlets{'remove-all-ext'} = <<'EOT';
+### Summary: Remove all file extensions, e.g. (file.html.gz) -> (file)
+s/(.+?)(?:\.\w{1,5})+$/$1/
+EOT
+
=head2 to-number
Rename files into numbers. Ex: (file1.txt, foo.jpg, quux.mpg) -> (1.txt, 2.jpg,
View
14 t/std_scriptlets-keep-one-ext.t
@@ -0,0 +1,14 @@
+#!perl
+
+use 5.010;
+use strict;
+use warnings;
+
+use Test::More tests => 1*2;
+use FindBin '$Bin';
+require "$Bin/testlib.pl";
+prepare_for_testing();
+
+test_perlmv(["a", "b.txt", "c.mp3.mp3", "d.html.gz"], {extra_opt=>"keep-one-ext"}, ["a", "b.txt", "c.mp3", "d.gz"], 'keep-one-ext');
+
+end_testing();
View
14 t/std_scriptlets-remove-all-ext.t
@@ -0,0 +1,14 @@
+#!perl
+
+use 5.010;
+use strict;
+use warnings;
+
+use Test::More tests => 1*2;
+use FindBin '$Bin';
+require "$Bin/testlib.pl";
+prepare_for_testing();
+
+test_perlmv(["a", "b.txt", "c.mp3.mp3"], {extra_opt=>"remove-all-ext"}, ["a", "b", "c"], 'remove-all-ext');
+
+end_testing();
View
14 t/std_scriptlets-remove-ext.t
@@ -0,0 +1,14 @@
+#!perl
+
+use 5.010;
+use strict;
+use warnings;
+
+use Test::More tests => 1*2;
+use FindBin '$Bin';
+require "$Bin/testlib.pl";
+prepare_for_testing();
+
+test_perlmv(["a", "b.txt", "c.mp3.mp3"], {extra_opt=>"remove-ext"}, ["a", "b", "c.mp3"], 'remove-ext');
+
+end_testing();
Please sign in to comment.
Something went wrong with that request. Please try again.