Created
February 14, 2012 11:23
-
-
Save kschiess/1825995 to your computer and use it in GitHub Desktop.
A textmate like folder search using picky. This is just a prototype.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
floere
commented
Feb 21, 2012
via email
I'm glad :)
One thing you can assume with Picky is that it's relatively fast - without
wanting to sound glib. When overriding internals be sure not to allocate
too many resources, especially in code that's called many times. But you
know all that already :)
Have fun! It's a great idea and I'd love to see it go somewhere!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment