Emacs の find インターフェース igrep.el。
これも海外サイトを見ていて見つけたもので、find コマンドを使って、サブディレクトリも grep 検索するコマンドを提供する Elisp です。
EmacsWiki: igrep.el にあるので、
M-x install-elisp <RET> http://www.emacswiki.org/cgi-bin/emacs/download/igrep.el <RET>
で、インストールできます。
.emacs の設定は、(require 'igrep) でもいいのですが、コメントに autoload の例があるのでこちらでも良いです。
(autoload 'igrep "igrep" "*Run `grep` PROGRAM to match REGEX in FILES..." t) (autoload 'igrep-find "igrep" "*Run `grep` via `find`..." t) (autoload 'igrep-visited-files "igrep" "*Run `grep` ... on all visited files." t) (autoload 'dired-do-igrep "igrep" "*Run `grep` on the marked (or next prefix ARG) files." t) (autoload 'dired-do-igrep-find "igrep" "*Run `grep` via `find` on the marked (or next prefix ARG) directories." t) (autoload 'Buffer-menu-igrep "igrep" "*Run `grep` on the files visited in buffers marked with '>'." t) (autoload 'igrep-insinuate "igrep" "Define `grep' aliases for the corresponding `igrep' commands." t)
なお、読み込む前に grep と find のあるパスを exec-path に設定しておかなければなりません。ただ、パスを設定していなくても、
(setq igrep-program "/opt/local/bin/grep") (setq igrep-find-program "/usr/bin/find")
のように、直接パスを書くことで、エラーを回避できます。
igrep-find。
igrep, fgrep, egrep の3つは、grep とほぼ同じです。コマンドを入力すると、マッチする文字列とファイルのグロブを聞かれますので、共に入力してエンタすると、マッチしたファイル一覧が表示されます。
まぁ、上記の3つのコマンドは、他の grep 系のコマンドと比べて別段大差ありませんが、これらのコマンドに -find を付けると、find を使ってサブディレクトリも検索してくれるようになります。
C-c C-k で検索をキャンセルできます。
Mac だと xargs のオプションエラー?
igrep-find のときに、xargs を使って引数の処理をするのですが、コマンドオプションの -e がないというエラーが出てしまいます。
igrep-find-use-xargs という変数があり、xargs が使えるかどうかを調べてくれているようですが、-e オプションに関してはスルーの様です。
ですので、僕は 892 行目付近の xargs の引数を直接編集して -e を消してしまいました。
(format (cond ((eq igrep-find-use-xargs 'gnu) ;; | \\\n "%s %s %s %s %s -print0 | xargs -0 -e %s") (igrep-find-use-xargs ;; | \\\n "%s %s %s %s %s -print | xargs -e %s") (t "%s %s %s %s %s -exec %s %s")) igrep-find-program (mapconcat 'igrep-quote-file-name (nreverse directories) " ")
(setq igrep-find-use-xargs nil) としても良いと思うので、どちらが良いかはおまかせします。
rubikitch さんが EmacsWiki で相対パスの利用方のパッチ書いてた。
igrep for recursive grepping にありますた。