Skip to content

Instantly share code, notes, and snippets.

@tily
Created June 22, 2009 01:39
Show Gist options
  • Save tily/133761 to your computer and use it in GitHub Desktop.
Save tily/133761 to your computer and use it in GitHub Desktop.
simple launcher on Windows (umcomplete)
#!ruby
require 'optparse'
def main
keyword = ''
OptionParser.new do |opt|
opt.on('-s', '--search KEYWORD', String) {|v| keyword = v}
opt.parse!
end
launcher = WindowsLauncher.new
if(keyword != '')
commands = launcher.search(keyword)
commands.map {|c| puts c }
else
launcher.execute(ARGV[0])
end
end
class WindowsLauncher
def initialize
# TODO: add %PATH%
@commands = Dir::glob("/Program Files/*/*.exe")
end
def search(keyword)
@result = []
@commands.each do |command|
if command =~ /#{keyword}/i
@result.push(command)
end
end
return @result
end
def execute(keyword)
result = search(keyword)
exec(result[0])
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment