diff --git a/qwandry.rb b/qwandry.rb index f8e9eac..a14b7b5 100755 --- a/qwandry.rb +++ b/qwandry.rb @@ -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 \ No newline at end of file diff --git a/repositories.rb b/repositories.rb index 73fca32..e0568e1 100644 --- a/repositories.rb +++ b/repositories.rb @@ -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: