Since I moved from Windows to a Mac last year, one of the tools I have missed is the file search tool, Everything. IMO Everything is a brilliant search tool, since it is very light on resources and it just does what it advertises with a simple user interface.
It also worked well with the way I typically name my directory structure, area of work -> project -> subproject -> … So if I was looking for the architecture charts, say architecture.ppt for a project, in Everything, I could pop-up the window and simply type “work”, “project”, “subproject”, “architecture”, “ppt” in any order and have it show the file I was looking for.
On Macs, we have the default Spotlight search engine but I haven’t been able to figure out how to make it work well for my needs.
Everything script for Mac OSX
So, I came up with the following bit of shell-script to do the same. It is of course based on locate functionality.
#!/bin/bash cmd="locate -i $1" while [ $# -gt 0 ]; do cmd="$cmd | grep -i $1"; shift; done eval $cmd
Save the above in
~/bin/everything, and you can use it as following:
haider@thinkhr(555) % everything readme applescripts /Users/haider/MyDocs/org/tools/applescripts-readme.org /Users/haider/tools/AppleScripts/README.org /Users/haider/tools/AppleScripts/README.org~
Integration with Emacs
As I said earlier I am trying to use Emacs for all things I can. For now, the only things I have to move away to are for work email (IBM/Lotus Notes) and presentations (with Powerpoint). Net effect is that I am spending more and more time inside Emacs.
I have setup
F1 key as follows:
(global-set-key (kbd "<f1>") (lambda() (interactive) (helm :prompt "Switch to: " :candidate-number-limit 10 ;; up to 10 of each :sources '(helm-c-source-ffap-line helm-c-source-ffap-guesser helm-c-source-buffers-list ;; buffers helm-c-source-recentf ;; recent files helm-c-source-bookmarks ;; bookmarks helm-c-source-file-cache helm-c-source-files-in-current-dir ;; current dir helm-c-source-locate)))) ;; use 'locate'
Here is how the previously described
everything script comes in handy:
(setq helm-c-locate-command "~/bin/everything %.0s %s")
Using openwith for non-textual files
The above works perfectly for any files that are textual in nature, I can press F1, type in the search words and press enter to open it in Emacs.
Of course, I wanted to do the same for any other file and open it with the right application. That’s where Markus Triska’s openwith package comes in handy. Download and install it, and set it up as follows:
;; openwith setup to help in find-file, etc. for common file types (require 'openwith) (openwith-mode t) (setq openwith-associations (quote (("\\.pdf\\'" "open" (file)) ("\\.svg\\'" "open" (file)) ("\\.\\(?:mpe?g\\|avi\\|wmv\\)\\'" "open -a vlc" (file)) ("\\.\\(?:jp?g\\|png\\)\\'" "open" (file)) ("\\.ppt[x]*\\'" "open" (file)) ("\\.doc[x]*\\'" "open" (file)) ("\\.xls[x]*\\'" "open" (file)) )))
This is what I love about the Unix and Emacs ecosystems. You can combine and use a number of tools to provide a missing functionality, and build something very useful.
As I said at the start, I was missing
Everything functionality when I moved to Mac. I googled around but couldn’t find anything perfect for my needs. Hope this helps someone else looking for same.