Created
January 10, 2009 23:05
-
-
Save miyagawa/45580 to your computer and use it in GitHub Desktop.
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/perl | |
use strict; | |
use warnings; | |
use File::Basename qw(basename); | |
my($key, @files) = @ARGV; | |
for my $f (@files) { | |
my $domain = domain_for($f) || "default"; | |
$domain = "default" if $domain eq '*'; | |
$domain =~ s/^www\.//; | |
my $dir = "root/plugins/$domain"; | |
mkdir $dir, 0777 unless -e $dir; | |
my($ext) = $f =~ /\.(\w+)$/; | |
my $target; | |
if ($domain eq 'default') { | |
$target = "$dir/$key-" . basename($f); | |
} else { | |
$target = "$dir/$key.$ext"; | |
} | |
system "git-mv $f $target"; | |
} | |
sub domain_for { | |
my $file = shift; | |
open my $in, "<", $file or die "$file: $!"; | |
while (<$in>) { | |
/domain: (\S+)/ and return $1; | |
/{domain} = ["'](.*?)["']/ and return $1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment