refining repositories a little, there are a few common layouts. We will start with flat ones.
This commit is contained in:
parent
8062659921
commit
e6a23d045b
24
qwandry.rb
24
qwandry.rb
|
@ -17,6 +17,24 @@ if ARGV.length != 1
|
||||||
exit(-1)
|
exit(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
class Repository
|
||||||
|
def initialize(path)
|
||||||
|
@path = path.chomp('/')
|
||||||
|
end
|
||||||
|
|
||||||
|
def scan(name)
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class FlatRepository < Repository
|
||||||
|
def scan(name)
|
||||||
|
Dir["#{@path}/*"].select{|path| path if File.basename(path).start_with?(name)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
load('repositories.rb')
|
load('repositories.rb')
|
||||||
|
|
||||||
name = ARGV.pop
|
name = ARGV.pop
|
||||||
|
@ -24,7 +42,7 @@ candidates = []
|
||||||
|
|
||||||
@repositories.each do |set, repos|
|
@repositories.each do |set, repos|
|
||||||
repos.each do |repo|
|
repos.each do |repo|
|
||||||
Dir["#{repo}/*"].each{|path| candidates << path if File.basename(path).start_with?(name)}
|
candidates.concat(repo.scan(name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,6 +51,6 @@ candidates.each_with_index do |path, index|
|
||||||
end
|
end
|
||||||
|
|
||||||
print ">> "
|
print ">> "
|
||||||
index = gets
|
index = gets.to_i-1
|
||||||
path = candidates[index.to_i-1]
|
path = candidates[index]
|
||||||
`mate #{path}`
|
`mate #{path}`
|
|
@ -4,15 +4,11 @@ def which(bin)
|
||||||
`which #{bin}`.chomp
|
`which #{bin}`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(repository, path=nil)
|
def add(label, path)
|
||||||
if !path
|
@repositories[label.to_s] << FlatRepository.new(path)
|
||||||
path = repository
|
|
||||||
repository = 'default'
|
|
||||||
end
|
|
||||||
|
|
||||||
@repositories[repository] << path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if which('ruby') == '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/bin/ruby'
|
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 :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
|
end
|
Loading…
Reference in New Issue