From 8062659921250c3e9146737753246e9f27aae469 Mon Sep 17 00:00:00 2001 From: Adam Sanderson Date: Thu, 5 Aug 2010 07:41:35 -0700 Subject: [PATCH] Quick and dirty spike. Mocked up a working version, next up... code that is not terrible. --- qwandry.rb | 38 ++++++++++++++++++++++++++++++++++++++ repositories.rb | 18 ++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 qwandry.rb create mode 100644 repositories.rb diff --git a/qwandry.rb b/qwandry.rb new file mode 100755 index 0000000..8fe48d5 --- /dev/null +++ b/qwandry.rb @@ -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}` \ No newline at end of file diff --git a/repositories.rb b/repositories.rb new file mode 100644 index 0000000..4d75290 --- /dev/null +++ b/repositories.rb @@ -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 \ No newline at end of file