-
Notifications
You must be signed in to change notification settings - Fork 215
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
7 changed files
with
182 additions
and
5 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
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
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,61 @@ | ||
module Sizes | ||
GIGA_SIZE = 1073741824.0 | ||
MEGA_SIZE = 1048576.0 | ||
KILO_SIZE = 1024.0 | ||
@command_string = "" | ||
|
||
# Return the file size with a readable style. | ||
def Sizes.readable_file_size(size, precision) | ||
case | ||
when size == 1 | ||
return "1 B" | ||
when size < KILO_SIZE | ||
return "%d B" % size | ||
when size < MEGA_SIZE | ||
return "%.#{precision}f KB" % (size / KILO_SIZE) | ||
when size < GIGA_SIZE | ||
return "%.#{precision}f MB" % (size / MEGA_SIZE) | ||
else | ||
return "%.#{precision}f GB" % (size / GIGA_SIZE) | ||
end | ||
end | ||
|
||
def self.show_sizes(where) | ||
#puts "your command: #{@command_string}" | ||
pipe = IO.popen("du -s #{ where } | sort -n") | ||
while (line = pipe.gets) | ||
match = line.match(/^(\d+)\s+.+?$/) | ||
if match | ||
puts "#{ Sizes.readable_file_size(match[1].to_i, 2) } #{ line }" | ||
else | ||
puts line | ||
end | ||
end | ||
end | ||
|
||
def self.size_stuff(command) | ||
@command_string = command | ||
match = command.match(/^show\s+(?:size|disk|usage)\s+for\s+(.+?)$/i) || command.match(/^what[^\s]*\s+(?:the|)\s*(?:size|space)\s+(?:for|in|of)\s+(.+?)$/i) | ||
|
||
if match | ||
where = match[1].strip | ||
is_this_directory = where == '.' || where.downcase.match(/^(this\s+)?(?:dir(?:ectory)|folder|path)?$/) | ||
|
||
{ | ||
:call => lambda {self.show_sizes(is_this_directory ? '.' : where )}, | ||
:explanation => "Shows the size of files in #{ is_this_directory ? 'all the files in the current directory, including subdirectories' : where }." | ||
} | ||
end | ||
end | ||
|
||
def self.interpret(command) | ||
responses = [] | ||
|
||
sizes_command = self.size_stuff(command) | ||
responses << sizes_command if sizes_command | ||
|
||
responses | ||
end | ||
end | ||
|
||
$executors << Sizes |
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,75 @@ | ||
module Spotify | ||
|
||
def self.start(command) | ||
matching = command.match(/^(start|resume|play)\s+(spotify|((?:the|my)\s+)?music)$/i) | ||
|
||
if matching | ||
{ | ||
:command => "osascript -e 'tell application \"spotify\" to play'", | ||
:explanation => "Starts playing spotify." | ||
} | ||
else | ||
nil | ||
end | ||
end | ||
|
||
def self.pause(command) | ||
matching = command.match(/^pause\s+(spotify|((?:the|my)\s+)?music)$/i) | ||
|
||
if matching | ||
{ | ||
:command => "osascript -e 'tell application \"spotify\" to pause'", | ||
:explanation => "Pauses spotify." | ||
} | ||
else | ||
nil | ||
end | ||
end | ||
|
||
def self.next(command) | ||
matching = command.match(/^(next|advance)\s+(song|music|track|spotify)$/i) | ||
|
||
if matching | ||
{ | ||
:command => "osascript -e 'tell application \"spotify\" to next track'", | ||
:explanation => "Makes spotify play the next track." | ||
} | ||
else | ||
nil | ||
end | ||
end | ||
|
||
def self.prev(command) | ||
matching = command.match(/^prev(?:ious)?\s+(song|music|track|spotify)$/i) | ||
|
||
if matching | ||
{ | ||
:command => "osascript -e 'tell application \"spotify\" to previous track'", | ||
:explanation => "Makes spotify play the previous track." | ||
} | ||
else | ||
nil | ||
end | ||
end | ||
|
||
|
||
def self.interpret(command) | ||
responses = [] | ||
|
||
start_command = self.start(command) | ||
responses << start_command if start_command | ||
|
||
pause_command = self.pause(command) | ||
responses << pause_command if pause_command | ||
|
||
next_command = self.next(command) | ||
responses << next_command if next_command | ||
|
||
prev_command = self.prev(command) | ||
responses << prev_command if prev_command | ||
|
||
responses | ||
end | ||
end | ||
|
||
$executors << Spotify |
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