Mercurial > ec-dotfiles
annotate bin/rmcrc @ 244:b6b9a47de016
Turns out solaris doesn't have [
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 07 Nov 2011 12:26:10 +0700 |
parents | 66c32422a3d4 |
children |
rev | line source |
---|---|
88
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
1 #!/usr/bin/env perl |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
2 |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
3 use warnings; |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
4 use strict; |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
5 use File::Basename; |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
6 |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
7 my @files = @ARGV or print("Usage: ",basename($0)," file1 ... fileN\n") && exit(1); |
116 | 8 my $skip=0; |
88
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
9 foreach (@files) { |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
10 print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_; |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
11 my $newname = $_; |
115
7c3cdb235bbb
The reverse of putcrc: rmcrc.
Edho Prima Arief <edho@myconan.net>
parents:
88
diff
changeset
|
12 $newname =~ s/\[[[:xdigit:]]{8}\]//i; |
7c3cdb235bbb
The reverse of putcrc: rmcrc.
Edho Prima Arief <edho@myconan.net>
parents:
88
diff
changeset
|
13 $newname =~ s/ *(\.\w+)$/$1/; |
88
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
14 print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname; |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
15 if ($_ eq $newname) { |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
16 print("$_: no need to rename, skipping\n"); |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
17 } else { |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
18 if($skip==1) { print("Result: $_ --> $newname\n"); } |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
19 else { |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
20 if(rename($_, $newname)) { print("$_ -> $newname\n"); } |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
21 else { print("$_: rename failed\n"); } |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
22 } |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
23 } |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
24 next(); |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
25 } |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
26 |
917b525eaee0
Put [End] to files. Still in perl D:
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
27 exit(0); |