Adding recipes
This commit is contained in:
parent
6bdbbcad3b
commit
22ec2aa217
8
README
8
README
@ -1,8 +0,0 @@
|
||||
Qwandry, a questionable tool
|
||||
=============================
|
||||
Why spend time trying to remember where libraries, projects, and packages are lurking,
|
||||
when your computer already knows?
|
||||
|
||||
qw activerecord # open the activerecord gem
|
||||
qw matrix # open the ruby standard library matrix file
|
||||
|
31
README.markdown
Normal file
31
README.markdown
Normal file
@ -0,0 +1,31 @@
|
||||
Qwandry, a questionable tool
|
||||
=============================
|
||||
|
||||
Why spend time trying to remember where libraries, projects, and packages are
|
||||
lurking when your computer can do it faster?
|
||||
|
||||
qw activerecord # open the activerecord gem
|
||||
qw matrix # open the ruby standard library matrix file
|
||||
|
||||
Installation
|
||||
------------
|
||||
Qwandry is a standard ruby gem, on any system with ruby installed already
|
||||
simply install with:
|
||||
|
||||
gem install qwandry
|
||||
|
||||
The gem will install the most recent version of Qwandry, and add the `qw`
|
||||
script to your `PATH`.
|
||||
|
||||
Usage
|
||||
-----
|
||||
Just type `qw` and the first few letters of what you're looking for. By
|
||||
default Qwandry is set up for locating and editing ruby libraries.
|
||||
|
||||
qw date # opens ruby's date library
|
||||
|
||||
Contact
|
||||
-------
|
||||
Adam Sanderson, netghost@gmail.com
|
||||
|
||||
Issues and Source: https://github.com/adamsanderson/qwandry
|
3
TODO
3
TODO
@ -1,2 +1,3 @@
|
||||
- Differentiate multiple similar matches (show path or repository label)
|
||||
- Recognize file idioms such as './file.rb' and matching "./file/" @done
|
||||
- Recognize file idioms such as './file.rb' and matching "./file/" @done
|
||||
- Custom recipes
|
42
bin/qw
42
bin/qw
@ -1,26 +1,29 @@
|
||||
#!/usr/bin/env ruby
|
||||
# Add qwandry's library to the load path
|
||||
$: << File.dirname(__FILE__) + '/../lib'
|
||||
$:.unshift File.dirname(__FILE__) + '/../lib'
|
||||
# Require it
|
||||
require "qwandry"
|
||||
require "qwandry.rb"
|
||||
|
||||
@qwandry = Qwandry::Launcher.new
|
||||
load('~/.qwandry/repositories.rb') if File.exists?('~/.qwandry/repositories.rb')
|
||||
recipe_paths = Dir[
|
||||
(ENV['HOME']||'')+'/.qwandry/*.rb', # custom recipes
|
||||
File.dirname(__FILE__)+'/../lib/qwandry/recipes/*.rb', # built in recipes
|
||||
]
|
||||
|
||||
opts = OptionParser.new do |opts|
|
||||
opts.banner = "Usage: qwandry [options] name"
|
||||
opts.separator ""
|
||||
|
||||
opts.on("-r", "--repo LABEL", "Only search in repository LABEL","Repositories:", *@qwandry.repositories.keys.map{|k| "* #{k}"}) do |label|
|
||||
if @qwandry.repositories.has_key? label
|
||||
@repository_label = label
|
||||
recipe_names = recipe_paths.map{|path| File.basename(path,'.rb')}.uniq
|
||||
opts.on("-r", "--recipe RECIPE", "Use paths from RECIPE","Recipes:", *recipe_names.map{|k| "* #{k}"}) do |recipe|
|
||||
if recipe_names.include?(recipe)
|
||||
@recipe = recipe
|
||||
else
|
||||
STDERR.puts "Repository '#{label}' in not available, searching all repositories"
|
||||
STDERR.puts "Recipe '#{recipe}' is not available, using default."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
opts.on("-e", "--editor EDITOR", "Use EDITOR to open the package") do |editor|
|
||||
@qwandry.editor = editor
|
||||
@editor = editor
|
||||
end
|
||||
|
||||
opts.on_tail("-h", "--help", "Show this message") do
|
||||
@ -30,14 +33,29 @@ opts = OptionParser.new do |opts|
|
||||
end
|
||||
|
||||
opts.parse! ARGV
|
||||
|
||||
if ARGV.length != 1
|
||||
puts opts
|
||||
exit(1)
|
||||
end
|
||||
|
||||
# Create launcher
|
||||
@qwandry = Qwandry::Launcher.new
|
||||
|
||||
# Configure default values
|
||||
@qwandry.editor = @editor if @editor
|
||||
|
||||
# Load recipe
|
||||
@recipe ||= 'default'
|
||||
@recipe_path = recipe_paths.find{|p| File.basename(p,'.rb') == @recipe }
|
||||
unless @recipe_path
|
||||
STDERR.puts "Could not find recipe '#{@recipe}'"
|
||||
exit(1)
|
||||
end
|
||||
# Configure @qwandry
|
||||
@qwandry.instance_eval(File.read(@recipe_path) )
|
||||
|
||||
name = ARGV.pop
|
||||
packages = @qwandry.find(name,@repository_label)
|
||||
packages = @qwandry.find(name)
|
||||
|
||||
package = nil
|
||||
case packages.length
|
||||
|
@ -10,8 +10,6 @@ module Qwandry
|
||||
|
||||
def initialize
|
||||
@repositories = Hash.new{|h,k| h[k] = []}
|
||||
add_ruby_repositories
|
||||
add_gem_repositories
|
||||
end
|
||||
|
||||
# Adds a repository path to Qwandry's Launcher.
|
||||
@ -23,10 +21,9 @@ module Qwandry
|
||||
end
|
||||
|
||||
# Searches all of the loaded repositories for `name`
|
||||
def find(name,repository_label=nil)
|
||||
def find(name)
|
||||
packages = []
|
||||
@repositories.each do |label, repos|
|
||||
next if repository_label && repository_label != label
|
||||
repos.each do |repo|
|
||||
packages.concat(repo.scan(name))
|
||||
end
|
||||
@ -39,24 +36,5 @@ module Qwandry
|
||||
editor ||= @editor || ENV['VISUAL'] || ENV['EDITOR']
|
||||
system editor, *package.paths
|
||||
end
|
||||
|
||||
private
|
||||
# Add ruby standard libraries, ignore the platform specific ones since they
|
||||
# tend to contain only binaries
|
||||
def add_ruby_repositories
|
||||
($:).grep(/lib\/ruby/).reject{|path| path =~ /#{RUBY_PLATFORM}$/}.each do |path|
|
||||
add :ruby, path, Qwandry::LibraryRepository
|
||||
end
|
||||
end
|
||||
|
||||
# Add gem repositories:
|
||||
# Using the ruby load paths, determine the common gem root paths, and add those.
|
||||
# This assumes gem paths look like:
|
||||
def add_gem_repositories
|
||||
($:).grep(/gems/).map{|p| p[/.+\/gems\//]}.uniq.each do |path|
|
||||
add :gem, path
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
20
lib/qwandry/recipes/default.rb
Normal file
20
lib/qwandry/recipes/default.rb
Normal file
@ -0,0 +1,20 @@
|
||||
# Default recipe, adds ruby sources to Qwandry.
|
||||
|
||||
# Ensure that rubygems is on the path so we can search it
|
||||
require 'rubygems'
|
||||
|
||||
# Get all the paths on ruby's load path:
|
||||
paths = $:
|
||||
|
||||
# Reject binary paths, we only want ruby sources:
|
||||
paths = paths.reject{|path| path =~ /#{RUBY_PLATFORM}$/}
|
||||
|
||||
# Add ruby standard libraries:
|
||||
paths.grep(/lib\/ruby/).each do |path|
|
||||
add :ruby, path, Qwandry::LibraryRepository
|
||||
end
|
||||
|
||||
# Add gem repositories:
|
||||
($:).grep(/gems/).map{|p| p[/.+\/gems\//]}.uniq.each do |path|
|
||||
add :gem, path
|
||||
end
|
Loading…
Reference in New Issue
Block a user