#!/usr/bin/env ruby # # Uses the appropriate tool to unpack the files given # class Unpack def initialize @motions = false end def unpack(file) cmd = nil if file.match /\.tar\.gz$/ cmd = "tar xvfz" elsif file.match /\.tgz$/ cmd = "tar xvfz" elsif file.match /\.tar$/ cmd = "tar xvf" elsif file.match /\.gz$/ cmd = "gunzip" elsif file.match /\.zip$/ cmd = "unzip" elsif file.match /\.bzip2$/ cmd = "bunzip2" elsif file.match /\.bz2$/ cmd = "bunzip2" elsif file.match /\.jar$/ cmd = "jar xvf" else STDERR.puts "Couldn't find tool for " + file return end command = cmd + " " + file if @motions STDERR.puts command else exec command end end def main(argv) files = [] argv.each do |arg| if File.exist? arg files << arg else if arg == "-n" @motions = true end end end files.map {|file| unpack file} end end Unpack.new.main ARGV