Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save naoyat/351544 to your computer and use it in GitHub Desktop.
Save naoyat/351544 to your computer and use it in GitHub Desktop.
unzip とか tar とかで、解凍するアーカイブファイルとしてURLを直接指定したい
#!/usr/bin/env perl
#
# unzip とか tar とかで、解凍するアーカイブファイルとしてURLを直接指定したい
#
# $HOME/bin とかに unzip ないし tar という名前で保存し chmod +x しておく。
# $HOME/bin を環境変数PATHの冒頭に指定すること
#
use strict;
use File::Basename;
my @cmd = ("/usr/bin/".basename($0));
my $tmpdir = "/tmp";
my @tmpfiles = ();
foreach (@ARGV) {
if (/\Ahttps?:\/\//) {
my $tmpfile = $tmpdir . "/" . basename($_);
system("rm -f $tmpfile");
system("cd $tmpdir ; wget --quiet $_");
push @cmd, $tmpfile;
push @tmpfiles, $tmpfile;
} else {
push @cmd, $_;
}
}
print "@cmd\n";
system("@cmd");
foreach (@tmpfiles) {
unlink;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment