Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created May 2, 2014 14:46
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttscoff/11476891 to your computer and use it in GitHub Desktop.
Save ttscoff/11476891 to your computer and use it in GitHub Desktop.
A Sentaku-based wrapper for mdfind
#!/usr/bin/ruby
require 'shellwords'
query = ARGV.length > 0 ? ARGV.join(" ") : "date:today"
files = %x{mdfind '#{ARGV.join(" ")}'}.split("\n")[0..100]
filehash = {}
files.each {|file|
base = File.basename(file)
dir = File.dirname(file)
filehash["#{base} (#{dir})"] = file
}
menu = filehash.keys.join("\n")
res = %x{echo #{Shellwords.escape(menu)}|#{File.dirname(__FILE__)}/sentaku -s "line"}
unless res == ""
print "What command? (Enter to `open`): "
command = STDIN.gets.chomp
command = "open" if command == ""
puts %x{#{command} #{Shellwords.escape(filehash[res])}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment