Added optional custom repository.rb and made qwandry pick the package if there is only one match.

This commit is contained in:
Adam Sanderson 2010-08-16 21:04:29 -07:00
parent a9152515c6
commit c59a690643
2 changed files with 19 additions and 16 deletions

View File

@ -62,10 +62,16 @@ module Qwandry
end
end
def launch(package)
`mate #{package.paths.join(' ')}`
end
module_function :launch
end
if __FILE__ == $0
load('repositories.rb')
load('~/.qwandry/repositories.rb') if File.exists?('~/.qwandry/repositories.rb')
opts = OptionParser.new do |opts|
opts.banner = "Usage: qwandry [options] name [version]"
@ -93,13 +99,19 @@ if __FILE__ == $0
packages.concat(repo.scan(name))
end
end
package = nil
if packages.length == 1
package = packages.first
else
packages.each_with_index do |package, index|
puts "%3d. %s" % [index+1, package.name]
end
packages.each_with_index do |package, index|
puts " #{index+1}. #{package.name}"
print ">> "
index = gets.to_i-1
package = packages[index]
end
print ">> "
index = gets.to_i-1
package = packages[index]
`mate #{package.paths.join(' ')}` if package
Qwandry.launch package if package
end

View File

@ -1,19 +1,10 @@
@repositories = Hash.new{|h,k| h[k] = []}
def which(bin)
`which #{bin}`.chomp
end
def add(label, path, repository_type=Qwandry::FlatRepository)
label = label.to_s
@repositories[label] << repository_type.new(label, 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/'
# add :ruby, '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/lib/ruby/1.9.1/'
#end
# Add gem repositories:
# Using the ruby load paths, determine the common gem root paths, and add those.
# This assumes gem paths look like: