diff --git a/README.md b/README.md index 52a34f1..ba0c5c6 100755 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ The following is a non-exhaustive list of things you can do: betty uncompress something.tar.gz betty unarchive something.tar.gz to somedir (You can use unzip, unarchive, untar, uncompress, and expand interchangeably.) + betty compress /path/to/dir iTunes betty mute itunes diff --git a/lib/internet.rb b/lib/internet.rb index ae48c71..9072d1a 100755 --- a/lib/internet.rb +++ b/lib/internet.rb @@ -31,6 +31,19 @@ def self.uncompress(command) } end end + + def self.compress(command) + match = command.match(/^(?:zip|archive|tar gzip|gzip tar|compress)\s+([^\s]+)(\s+(?:directory|dir|folder|path))?$/i) + + if match + what_file = match[1].strip + + { + :command => "cd #{what_file}; tar -czvf #{what_file}.tar.gz *" + :explanation => "Compress the contents of #{what_file} directory, outputting the compressed file to parent directory" + } + end + end def self.interpret(command) responses = [] @@ -40,6 +53,9 @@ def self.interpret(command) uncompress_command = self.uncompress(command) responses << uncompress_command if uncompress_command + + compress_command = self.compress(command) + responses << compress_command if compress_command responses end