Quick and dirty spike. Mocked up a working version, next up... code that is not terrible.
This commit is contained in:
commit
8062659921
38
qwandry.rb
Executable file
38
qwandry.rb
Executable file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'optparse'
|
||||
|
||||
puts "Qwandry; a qwestionable tool"
|
||||
opts = OptionParser.new do |opts|
|
||||
opts.banner = "Usage: qwandry [options] [type] repository-name"
|
||||
|
||||
opts.separator ""
|
||||
opts.separator "Known Repositories:"
|
||||
# ...
|
||||
end
|
||||
|
||||
opts.parse! ARGV
|
||||
|
||||
if ARGV.length != 1
|
||||
puts opts
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
load('repositories.rb')
|
||||
|
||||
name = ARGV.pop
|
||||
candidates = []
|
||||
|
||||
@repositories.each do |set, repos|
|
||||
repos.each do |repo|
|
||||
Dir["#{repo}/*"].each{|path| candidates << path if File.basename(path).start_with?(name)}
|
||||
end
|
||||
end
|
||||
|
||||
candidates.each_with_index do |path, index|
|
||||
puts " #{index+1}. #{File.basename path}"
|
||||
end
|
||||
|
||||
print ">> "
|
||||
index = gets
|
||||
path = candidates[index.to_i-1]
|
||||
`mate #{path}`
|
18
repositories.rb
Normal file
18
repositories.rb
Normal file
@ -0,0 +1,18 @@
|
||||
@repositories = Hash.new{|h,k| h[k] = []}
|
||||
|
||||
def which(bin)
|
||||
`which #{bin}`.chomp
|
||||
end
|
||||
|
||||
def add(repository, path=nil)
|
||||
if !path
|
||||
path = repository
|
||||
repository = 'default'
|
||||
end
|
||||
|
||||
@repositories[repository] << path
|
||||
end
|
||||
|
||||
if which('ruby') == '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/bin/ruby'
|
||||
add 'gem', '/Users/adam/.rvm/gems/ruby-1.9.1-p378/gems/'
|
||||
end
|
Loading…
Reference in New Issue
Block a user