aboutsummaryrefslogtreecommitdiff
path: root/sanerename.pl
blob: b607a5d350488a4241139b2ddd4312d30a828ed8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl -w

# sanerename.pl by Urchlay

if($ARGV[0] eq '--fake') {
	shift;
	$fake++;
}

if(!@ARGV) {
	while(<>) {
		chomp;
		push @ARGV, $_;
	}
}

for(@ARGV) {
	my $o = $_;
	$_ = lc $_;
	s/(\w+)'(t|s)/${1}${2}/g; # de-apostrophize can't, don't, billy's, etc...
	s/\s+/ /g;
	s/\s-\s/-/;
	s/[\s`~!\@#\$%^&*()=+{}\[\]|\\;:'",<>?]/_/g;
	s/_+/_/g;
	s/_\././;
	s/_-_/-/g;
	if(-f $_) {
		warn "$_ already exists, not renaming `$o'\n";
	} else {
		if($fake) {
			warn "$o => $_\n";
		} else {
			rename $o, $_;
		}
	}
}