Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Created January 10, 2009 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyagawa/45580 to your computer and use it in GitHub Desktop.
Save miyagawa/45580 to your computer and use it in GitHub Desktop.
#!/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