The Silver Searcher のビルド手順 for gnupack

検索ツールといえば find & grep ですが、より優れている `The Silver Searcher' という検索ツールがあることを最近知りました。
使ってみないとどんなものなのかわからないので実際に導入してみました。

ちなみに、`The Silver Searcher' のことを通称 ag 呼ぶみたいです。なんの略?

2013/03/30 追記

agは元素記号の銀を意味するとのこと。The "Silver" Searcher だからか。

環境

導入の流れ

ag のソースを落としてきます
$ git clone git://github.com/ggreer/the_silver_searcher.git
ag のビルドに必要なパッケージのインストールをします
$ cyg-pm install -require zlib-devel pcre pkg-config 
ビルド
$ cd the_silver_searcher && ./build.sh && make install

これで、/usr/local/bin にag.exeがインストールされます。

使い方

ターミナル上で

$ ag hoge ~/fuga

と入力すれば、~/fuga ディレクトリ以下にあるhogeを含むファイルの一覧が検索され、結果が出力されます。
実際にこんな感じで出力されます。手軽で便利ですね。

$ ag setq ~/.emacs.d/conf/
/home/.emacs.d/conf/05_common-init.el
13:      (setq default-process-coding-system '(utf-8-unix . cp932-dos))
14:   ;;  (setq default-process-coding-system '(cp932 . cp932))
15:   ;;  (setq default-process-coding-system '(cp932 . utf-8-unix))
19:  (setq default-process-coding-system '(utf-8-unix . utf-8-unix)))
59:(setq frame-title-format "%f %Z")
68:(setq truncate-lines nil)
71:(setq truncate-partial-width-windows t)
75:(setq uniquify-buffer-name-style 'forward)
76:(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
77:(setq uniquify-ignore-buffers-re "*[^*]+*")
86:(setq linum-delay t)
95:(setq linum-format "%3d")
114:(setq display-time-24hr-format t)
115:(setq display-time-string-forms '(24-hours ":" minutes))
147:(setq-default save-place t)
151:(setq scroll-preserve-screen-position t)
154:(setq vertical-centering-font-regexp ".*")

色々と細かい指定もできるようなので詳細は ag -h を見てみてください。

emacsで使いたい

便利なものは是非emacsでも利用したいものですね。
既にemacs用のインターフェースを用意してくれている方がいますのでそれをするのが良いでしょう。

私はhelmを利用しているのでemacs-helm-agを導入しました。
が、そのままでは動かなかったので少し変更を加えました。
もし動かない場合は以下を試してみてください。
GitHub - zqwell/emacs-helm-ag: The silver searcher with helm interface

helm-ag の導入手順

git からソースを入手
$ cd ~/.emacs.d/public_repos/
$ git clone git://github.com/zqwell/emacs-helm-ag.git
設定
(add-to-list 'load-path (expand-file-name "~/.emacs.d/public_repos/emacs-helm-ag"))
(when (require 'helm-ag nil t)
  (setq helm-ag-base-command "ag --nocolor --nogroup --ignore-case --line-numbers")
  ;; (setq helm-ag-command-option "--all-text")
  )
使い方