This post originated from an RSS feed registered with Ruby Buzz
by Ryan Davis.
Original Post: locate and spotlight
Feed Title: Polishing Ruby
Feed URL: http://blog.zenspider.com/index.rdf
Feed Description: Musings on Ruby and the Ruby Community...
locate and spotlight each have their pros and cons. I like both for different reasons, but recently I caught on to using mdfind (spotlight's command-line interface) to search for file-names only. It is still a little slower than locate (but not much) but always up to date:
(defun locate-make-mdfind-command-line (search-string)
(list "mdfind" (concat "kMDItemDisplayName=*" search-string "*")))
(defun spotlight ()
"Search for files by name using spotlight"
(interactive)
(let ((locate-command "mdfind")
(locate-make-command-line 'locate-make-mdfind-command-line))
(call-interactively 'locate nil)))
(defun spotlight-full ()
"Search using spotlight"
(interactive)
(let ((locate-command "mdfind"))
(call-interactively 'locate nil)))
If you're feeling adventurous, keep the first defun and set locate-command and locate-make-command-line via customize. I did that for a few weeks but I like the flexibility of having both available.