Skip to content

Instantly share code, notes, and snippets.

@patrickbkr
Created December 16, 2019 17:54
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 patrickbkr/53a7494d228888d466386448d30eb16e to your computer and use it in GitHub Desktop.
Save patrickbkr/53a7494d228888d466386448d30eb16e to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
unit sub MAIN($file-dir, Bool :$exec) {
#for $file-dir.IO.lines -> $file {
for $file-dir.IO.dir -> $file {
if $file.basename ~~ /
^
( rakudo | nqp | rakudo\-star )
\- (\d\d\d\d) <[ \. \- ]> (\d\d) [ <[ \. \- ]> (\d+) ]?
( <-[ \. ]>+ )?
\. ( sha256\.txt | asc | tar\.gz | tar\.gz\.asc | tar\.gz\.sha256\.txt | dmg | dmg\.asc | dmg\.sha256\.txt | msi | msi\.sha256\.txt | AppImage | exe )
$
/ {
my ($name, $v0, $v1, $v2, $desc, $ext) = $0, $1, $2, $3, $4, $5;
$desc //= '';
$desc ~~ s/ \s* x86[_64]? \s* //;
my $bits32 = $desc.contains: 'no JIT';
my $os = $ext eq any('msi', 'exe', 'msi.sha256.txt') ?? 'win' !!
$ext eq any('dmg', 'dmg.asc', 'dmg.sha256.txt') ?? 'macos' !!
'';
my $new = '';
if $os {
$new = "$name-$v0.$v1" ~ ($v2 ?? ".$v2" !! '') ~ '-01-' ~ $os ~ '-' ~ ($bits32 ?? 'x86' !! 'x86_64') ~ $desc ~ ".$ext";
}
else {
$new = $file.basename;
}
if $file.basename ne $new {
say "{$file.basename} -> $new";
if $exec {
$file.rename: $file.parent.add($new);
}
}
}
else {
say "Didn't match: $file";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment