Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions lib/fun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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 #{$~}"
Expand Down
24 changes: 24 additions & 0 deletions lib/git.rb
Original file line number Diff line number Diff line change
@@ -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
31 changes: 26 additions & 5 deletions lib/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
Expand Down
67 changes: 67 additions & 0 deletions lib/template.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions spec/fun_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions spec/git_spec.rb
Original file line number Diff line number Diff line change
@@ -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