Skip to content

Instantly share code, notes, and snippets.

@kschiess
Created February 14, 2012 11:23
Show Gist options
  • Select an option

  • Save kschiess/1825995 to your computer and use it in GitHub Desktop.

Select an option

Save kschiess/1825995 to your computer and use it in GitHub Desktop.
A textmate like folder search using picky. This is just a prototype.
require 'picky'
require 'facets'
require 'facets/array/combination.rb'
Picky.logger = Picky::Loggers::Silent.new
input = ARGV
Folder = Struct.new(:id, :name)
folders = Dir[ENV['HOME'] + "/**"].
each_with_index.map { |name, idx| Folder.new(idx, name) }
puts folders
include Picky # So we don't have to type Picky:: everywhere.
class Textmate < Partial::Strategy
def each_partial token, &block
token.split('/').each do |word|
chars = word.chars.to_a
1.upto(word.size) do |n|
chars.combination(n).each { |comb|
yield comb.join }
end
end
end
end
folder_index = Index.new(:folders) do
source folders
category :name, partial: Textmate.new
end
folder_index.index
puts
folder_search = Search.new folder_index
require 'pp'
result = folder_search.search input.join(' ')
puts result
pp result.allocations
@kschiess
Copy link
Copy Markdown
Author

Thanks for the rewrite, that saves it for me. My approach was all backward and you showed me how. Looks like I can use picky after all ;) And I can live with the left to right thing as it is for now, just need a quick simple search.

@floere
Copy link
Copy Markdown

floere commented Feb 21, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment