diff --git a/install.rb b/install.rb index 7b0a576..18e9a12 100755 --- a/install.rb +++ b/install.rb @@ -23,7 +23,7 @@ def ask(prompt="", newline=false) if Dir.exist? INSTALL_LOC # raise "~/betty already exists! Please manually remove if you want to proceed" else - COPY_COMMAND = 'cp -rf ' + Dir.pwd + ' ' + INSTALL_LOC + COPY_COMMAND = 'cp -rf ' + File.dirname(__FILE__) + ' ' + INSTALL_LOC print "Running `" + COPY_COMMAND + "`\n" system COPY_COMMAND end diff --git a/lib/fun.rb b/lib/fun.rb index 1744e76..6707db6 100755 --- a/lib/fun.rb +++ b/lib/fun.rb @@ -8,6 +8,19 @@ def self.interpret(command) } end + if command.match(/^superman\s+vs\s+batman$/i) + responses << { + say: [true,false].sample ? "Batman" : "Superman" + } + end + + if command.match(/^what\s+if\s+batman\s+does\snot\s+have\s+a?n?y?\s*kryptonite$/i) + responses << { + say: "Batman always has kryptonite" + } + end + + if command.match(/^open\s(the\s)?pod\sbay\sdoor(s)?$/i) responses << { :say => "I'm sorry, Dave. I'm afraid I can't do that." @@ -46,12 +59,6 @@ def self.interpret(command) } end - if command.match(/go home/) - responses << { - :command => "cd ~" - } - end - if command.match(/sing (.*)/) responses << { :command => "say -v cello #{$~}" diff --git a/lib/git.rb b/lib/git.rb new file mode 100755 index 0000000..b9d6581 --- /dev/null +++ b/lib/git.rb @@ -0,0 +1,24 @@ +module Git + def self.interpret(command) + responses = [] + + if command.match(/^undo\s+git\s+add$/i) + responses << { + :say => "To undo a single file use\n\ngit reset filespec\n\n\nTo undo ALL files added (i.e. you want to undo git add .) then use\n\ngit reset" + } + end + + responses + end + + def self.help + commands = [] + commands << { + :category => "Git", + :usage => ["undo git add"] + } + commands + end +end + +$executors << Git \ No newline at end of file diff --git a/lib/internet.rb b/lib/internet.rb index a51e581..2234fd6 100755 --- a/lib/internet.rb +++ b/lib/internet.rb @@ -23,17 +23,38 @@ def self.uncompress(command) if where.nil? where = what_file.split(".").first end + + #TODO: Get the "tar" bit as well as it might be a plain bzip2 og gzip file + if(what_file) + type = what_file.split(".").last + end + in_same_directory = where == '.' || where.downcase.match(/^((?:this|same)\s+)?(?:dir(?:ectory)|folder|path)?$/) + case type + when "gz" + operation = "tar -zxvf" + postOp = "-C " + when "bz2" + operation = "tar -jxvf" + postOp = "-C " + when "zip" + operation = "unzip" + postOp = "-d " + else + operation = "tar -zxvf" + postOp = "-C " + end + { - :command => "#{ in_same_directory ? '' : 'mkdir ' + where + ' && ' } tar -zxvf #{ what_file } #{ in_same_directory ? '' : '-C ' + where }".strip, + :command => "#{ in_same_directory ? '' : 'mkdir ' + where + ' && ' } #{ operation } #{ what_file } #{ in_same_directory ? '' : "#{ postOp }" + where }".strip, :explanation => "Uncompresses the contents of the file #{ what_file }, outputting the contents to #{ in_same_directory ? 'this directory' : where }." } end end def self.compress(command) - match = command.match(/^(zip|archive|tar gzip|gzip tar|tar bzip|bzip tar|tar bzip2|bzip2 tar|compress|tar|gzip|bzip)\s+([^\s]+)(?:\s+(?:directory|dir|folder|path))?(?:\s+(?:to\s+)?(.+))?$/i) + match = command.match(/^(zip|archive|tar gzip|gzip tar|tar bzip|bzip tar|tar bzip2|bzip2 tar|compress|tar|gzip|bzip|bzip2)\s+([^\s]+)(?:\s+(?:directory|dir|folder|path))?(?:\s+(?:to\s+)?(.+))?$/i) if match how = match[1] @@ -42,11 +63,11 @@ def self.compress(command) case how when "zip" - operation = "zip" + operation = "zip -r" type = ".zip" - when "tar bzip", "bzip tar", "tar bzip2", "bzip2 tar", "bzip" + when "tar bzip", "bzip tar", "tar bzip2", "bzip2 tar", "bzip", "bzip2" operation = "tar -cjvf" - type = ".tar.bz" + type = ".tar.bz2" else operation = "tar -czvf" type = ".tar.gz" diff --git a/lib/template.rb b/lib/template.rb new file mode 100644 index 0000000..bff84cd --- /dev/null +++ b/lib/template.rb @@ -0,0 +1,67 @@ +# +# This file is a template that is designed to give you a starting point for extending Betty +# Copy this file to what you want to extend Betty with. Personally I wrote this as a precursor to +# extending Betty to supporting git development so my first step would be +# +# cp lib/_template.rb lib/git.rb +# + +module Template + # + # If you need unit conversions or other meta methods you'd want to locate them here at the top to be consistent with the code base + # See process.rb for examples or convert.rb + + # + # You need a self.interpret method which grabs the command and deals with it + # + def self.interpret(command) + responses = [] + + # + # The guts generally boil down to one or more regular expression matcher against the user's command + # + # Remember to use \s+ as a token delimiter and use () for grouping + # + if command.match(/^$/) + search_term = $1.gsub(' ', '%20') + + # + # Build a hash of the possible responses to the user (Note :url is a new idea that I'm floating here) + # + # Your typical options are :command, :say, :explanation + # :command represents the command you want to give the user + # :say is something to be said out loud + # :explanation is what we're teaching the user + # :url is an web url where more details are available + # + # Use Command.browser(url) as a way to open a url + # + responses << { + :command => "", + :explanation => "" + } + end + + # + # Return responses + # + responses + end + + # + # The help structure + # + def self.help + commands = [] + commands << { + :category => "", + :description => '', + :usage => [""] + } + commands + end +end + +# this last line is where the magic actually happens; you need to take the executors and assign it to something that does the work +# here it is commented out since this is, well, a template +#$executors << Some Class Goes Here diff --git a/spec/fun_spec.rb b/spec/fun_spec.rb index 4ef29a9..8c24106 100644 --- a/spec/fun_spec.rb +++ b/spec/fun_spec.rb @@ -13,5 +13,13 @@ context 'sudo make me a sandwich' do it { responds_with say: "I think you meant to place sudo at the start of the command." } end + + context "what if batman does not have any kryptonite" do + it { responds_with say: "Batman always has kryptonite" } + end + + context "what if batman does not have kryptonite" do + it { responds_with say: "Batman always has kryptonite" } + end end diff --git a/spec/git_spec.rb b/spec/git_spec.rb new file mode 100644 index 0000000..3eeac9e --- /dev/null +++ b/spec/git_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe 'Fun' do + + context 'undo git add' do + it { responds_with say: "To undo a single file use\n\ngit reset filespec\n\n\nTo undo ALL files added (i.e. you want to undo git add .) then use\n\ngit reset" } + end + +end