Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev'
- Loading branch information
Showing
31 changed files
with
920 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Betty | ||
===== | ||
|
||
For more info, visit the Betty homepage at https://github.com/pickhardt/betty | ||
|
||
Copyright 2014 Betty | ||
|
||
Betty hereby licenses this project to you under the Apache License, | ||
version 2.0 (the "License"); you may not use this file except in | ||
compliance with the License. You may obtain a copy of the License at: | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations | ||
under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env ruby | ||
|
||
`complete -o bashdefault -o default -o filenames -o nospace -C ~/betty/autocomplete.rb betty` | ||
# This should be called only once upon installation, but it doesn't hurt if it gets called multiple times. | ||
|
||
if ARGV.length==0 | ||
puts "Betty: Autocomplete installed." | ||
exit | ||
end | ||
|
||
words = ARGV[1..-1].reverse.join(" ") | ||
last = ARGV[2] | ||
current = ARGV[1] | ||
|
||
if last == "betty" | ||
puts "count" if "count".start_with? current | ||
puts "find" if "find".start_with? current | ||
puts "show" if "show".start_with? current | ||
puts "what" if "what".start_with? current | ||
puts "convert" if "convert".start_with? current | ||
end | ||
|
||
if last == "count" | ||
puts "words" if "words".start_with? current | ||
puts "lines" if "lines".start_with? current | ||
puts "chars" if "chars".start_with? current | ||
end | ||
|
||
if last == "convert" | ||
`COMPREPLY=()` # default filename completion | ||
# `compgen ...` | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,51 @@ | ||
#!/usr/bin/env ruby | ||
require 'readline' | ||
|
||
|
||
def ask(prompt="", newline=false) | ||
prompt += "\n" if newline | ||
Readline.readline(prompt, true).squeeze(" ").strip | ||
end | ||
|
||
|
||
|
||
INSTALL_LOC = Dir.home + '/betty/' | ||
|
||
if Dir.exist? INSTALL_LOC | ||
raise "~/betty already exists! Please manually remove if you want to proceed" | ||
puts "Warning: ~/betty already exists!" | ||
end | ||
|
||
puts "We will install to ~/betty and put an alias in your .<shell>rc. Hit <enter> or 'y' if this is okay." | ||
STDOUT.flush | ||
CONTINUE = ask "> " | ||
if CONTINUE == "" || CONTINUE == "y" | ||
# copy to ~/betty/ | ||
COPY_COMMAND = 'cp -rf '+ Dir.pwd + ' ' + INSTALL_LOC | ||
print "Running `" + COPY_COMMAND + "`\n" | ||
system COPY_COMMAND | ||
|
||
# get current shell | ||
*junk, SHELL = `echo $SHELL`.split('/') | ||
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 | ||
print "Running `" + COPY_COMMAND + "`\n" | ||
system COPY_COMMAND | ||
end | ||
|
||
# writing the alias | ||
SHELLRC = (Dir.home + '/.' + SHELL.chomp + 'rc').chomp | ||
begin | ||
*junk, SHELL = `echo $SHELL`.split('/') | ||
rescue Exception | ||
SHELL="bash" #ruby 1.8 (parsing exceptions are not rescued by default) | ||
end | ||
bash_config = '.' + SHELL.chomp + 'rc' | ||
bash_config = '.bash_profile' if RUBY_PLATFORM.match /darwin/ #and ... ? | ||
|
||
SHELLRC = (Dir.home + '/' + bash_config ).chomp | ||
print "Writing an alias called `betty` to " + SHELLRC + "\n" | ||
open(SHELLRC, 'a') do |f| | ||
f.puts "\n" | ||
f.puts "######## Generated by Betty's install script" | ||
f.puts "alias betty=#{ Dir.home }/betty/main.rb" | ||
end | ||
|
||
puts "add auto-complete by typing" | ||
puts "complete -C #{INSTALL_LOC}autocomplete.rb betty" | ||
`#{INSTALL_LOC}autocomplete.rb` | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class String | ||
def numeric? | ||
Float(self) != nil rescue false | ||
end | ||
end | ||
|
||
module Calculate | ||
def self.interpret(command) | ||
responses = [] | ||
matches = command.match(/^what\s+is\s+(.+)\s+(.+)\s(.+)$/) | ||
|
||
if matches | ||
if (matches[1].numeric? && matches[3].numeric?) | ||
arg1 = matches[1] | ||
arg2 = matches[3] | ||
else | ||
return [] | ||
end | ||
|
||
oper = matches[2] | ||
if ["plus", "+"].include?(oper) | ||
op = "+" | ||
elsif ["minus", "-"].include?(oper) | ||
op = "-" | ||
elsif ["times", "*"].include?(oper) | ||
op = "*" | ||
elsif ["by", "divided", "divied by", "/"].include?(oper) | ||
op = "/" | ||
else | ||
return [] | ||
end | ||
|
||
responses << { | ||
command: "bc <<< #{arg1}#{op}#{arg2}", | ||
explanation: "Calculates #{arg1}#{op}#{arg2}" | ||
} | ||
end | ||
responses | ||
end | ||
|
||
def self.help | ||
commands = [] | ||
commands << { | ||
category: "Calculate", | ||
description: '\033[34mCalculate\033[0m', | ||
usage: ["- betty what is 40 plus 2"] | ||
} | ||
commands | ||
end | ||
end | ||
|
||
$executors << Calculate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require File.expand_path('../os.rb', __FILE__) | ||
|
||
module Command | ||
|
||
@@platform_error = "echo \"I don\'t know how to do that on #{OS.platform_name} yet, sorry !\"" | ||
|
||
#todo: complete for missing OSes | ||
def self.browser(link) | ||
browser = "" | ||
case OS.platform_name | ||
when 'OS X' | ||
browser = 'open' | ||
when 'Linux' | ||
browser = 'xdg-open' | ||
when 'Windows' | ||
browser = 'start' | ||
else | ||
return @@platform_error | ||
end | ||
return "#{ browser } #{ link }" | ||
end | ||
|
||
def self.bus(msg= {}) | ||
case OS.platform_name | ||
when 'OS X' | ||
if ! msg[:osx] | ||
return @@platform_error | ||
end | ||
return "osascript -e '#{ msg[:osx] }'" | ||
when 'Linux' | ||
if ! msg[:linux] | ||
return @@platform_error | ||
end | ||
return "dbus-send #{ msg[:linux] }" | ||
else | ||
return @@platform_error | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
module Conversion | ||
|
||
def self.detect_in_format f | ||
# todo : mapping latin1 -> ISO-8859-1 etc etc | ||
return f.gsub(/.*\./,"") | ||
end | ||
|
||
def self.detect_out_format f | ||
return f.gsub(/.*\./,"") | ||
end | ||
|
||
|
||
def self.interpret(command) | ||
responses = [] | ||
|
||
image_formats=%w[jpg bmp gif tif png] | ||
sound_formats=%w[wav mp3 flac au ogg] | ||
encoding_formats=%w[utf8 latin1 ascii ISO-8859-1 UTF-8] | ||
doc_formats=%w[doc pdf] | ||
# etc, todo | ||
|
||
convert_pattern=%r{ | ||
(convert|save|transform)\s | ||
(?<all>all\s)? | ||
(?<my>my\s)? | ||
(?<files>.*?)\s | ||
(to|as)\s | ||
(?<out>.*) | ||
}imx | ||
|
||
match=convert_pattern.match command | ||
return responses if not match | ||
|
||
in_files=match[:files] | ||
in_format=detect_in_format in_files | ||
out_format=detect_out_format match[:out] | ||
out_file=match[:out] if match[:out].length>3 | ||
out_file||=in_files.sub(/\.#{in_format}/,".#{out_format}") | ||
args = "" | ||
|
||
if match and encoding_formats.index out_format | ||
command="iconv " | ||
args="-f ISO-8859-1 -t UTF-8" | ||
args="-f #{in_format} -t #{out_format}" | ||
end | ||
|
||
if match and image_formats.index out_format | ||
command="sips -s format" | ||
args = out_format + " " | ||
args += in_files + " " | ||
args += " --out " + out_file | ||
# OR: alias resize-image='/opt/local/bin/convert in.jpg -resize 231x231 out.jpg' | ||
end | ||
|
||
if match and sound_formats.index out_format | ||
command="ffmpeg" | ||
command="sox" if in_format=="raw"|| in_format=="pcm" | ||
args="-i #{in_files} #{out_file}" | ||
args="-t raw -r 8000 -e signed -b 16 -c 1" if in_format=="raw" | ||
args="-t raw -r 16k -e signed -b 8 -c 1" if in_format=="pcm" | ||
# function m4a_TO_mp3(){ | ||
# open "http://media.io/" | ||
# } | ||
end | ||
|
||
responses << { | ||
:command => "#{command} #{args}", | ||
:explanation => "Convert #{in_files} to #{out_format}" | ||
} | ||
|
||
return responses | ||
end | ||
|
||
def self.help | ||
commands = [] | ||
commands << { | ||
:category => "Conversion", | ||
:description => '\033[34mConvert\033[0m all kinds of files', | ||
:usage => ["convert img.jpg to bmp", | ||
"convert song.wav to mp3"] | ||
} | ||
commands | ||
end | ||
end | ||
|
||
$executors << Conversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.