Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created November 15, 2011 05:06
Show Gist options
  • Select an option

  • Save nbqx/1366209 to your computer and use it in GitHub Desktop.

Select an option

Save nbqx/1366209 to your computer and use it in GitHub Desktop.
require 'rubygems/user_interaction'
class Jump
include Gem::UserInteraction
def ask_me
n = ask "key?"
end
def choose(lst)
ret = ""
if lst.length==1
ret = lst.first
else
n = choose_from_list("#{lst.length} files", lst)
ret = n.first
end
puts ret
end
trap("INT"){ exit }
end
j = Jump.new
home = File.expand_path "~/"
lib = File.expand_path "~/Library"
word = j.ask_me
res = (`mdfind 'kMDItemContentType == \"public.folder\" && kMDItemDisplayName == \"*#{word}*\"wcd'`).split("\n")
j.choose res.select{|x| x =~ /^#{home}/}.reject{|x| x=~ /^#{lib}/}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment