The Silver Searcher

提供: FreeBSD入門
移動: 案内検索
スポンサーリンク

The Silver Searcher (ag)とは、ackよりも高速なgrepのようなパターン検索のソフトウェアです。

読み方

The Silver Searcher
ざ しるばー さーちゃー

概要

The Silver Searcherのコマンドは、ag です。

なぜ ag は素晴らしいのか?

  • コードのサーチで ackよりも3-5倍高速です
  • .gitignore , .hgignore からファイルパターンを無視します。
  • ソースコードリポジトリを検索するときに、検索対象にしたくないパターンを .aginore に追加できます。
  • ackよりコマンド名が33%短いです。すべてのキーがホームポジションにあります。

なぜ高速なのか?

  • リテラル(非正規表現)の検索には、 Boyer-Moore-Horspool strstr を使用します。
  • ファイルは、バッファを読む代わりに mmap() を使用します。
  • pcre 8.21 以降を使用し、ビルドしています。正規表現(regex)検索は、 JIT コンパイラを使用します。
  • ag は、膨大なファイルに対する正規表現の実行前に pcre_study() を呼び出します。
  • 無視ファイルのすべてのパターンにたいして、 fnmatch() を呼ぶ代わりに、非正規表現パターンは、配列とバイナリ検索にロードします。
  • ag は、並列のファイル検索とマルチCPUコレのアドバンテージのために pthread を使用します。

インストール

FreeBSDにインストールする場合

ports コレクションからインストールする場合

cd /usr/ports/textproc/the_silver_searcher
sudo make install clean

pkgコマンドでインストールする場合

sudo pkg install the_silver_searcher

portinstallコマンドでインストールする場合

sudo portinstall /usr/ports/textproc/the_silver_searcher
root@b0:~ # pkg search the_silver_searcher
the_silver_searcher-0.17
root@b0:~ # pkg search -f the_silver_searcher
the_silver_searcher-0.17
Name           : the_silver_searcher
Version        : 0.17
Origin         : textproc/the_silver_searcher
Architecture   : freebsd:10:x86:32
Prefix         : /usr/local
Categories     : textproc
Maintainer     : gslin@gslin.org
WWW            : https://github.com/ggreer/the_silver_searcher
Comment        : A code-searching tool similar to ack but faster
Shared Libs required:
        libpcre.so.3
Flat size      : 42.3KiB
Pkg size       : 21 KB
Description    :
An attempt to make something better than ack, which itself is better than
grep.
 
WWW: https://github.com/ggreer/the_silver_searcher
root@b0:~ # pkg install the_silver_searcher
Updating repository catalogue
The following 1 packages will be installed:
 
        Installing the_silver_searcher: 0.17
 
The installation will require 42 KB more space
 
21 KB to be downloaded
 
Proceed with installing packages [y/N]: y
the_silver_searcher-0.17.txz        100%   21KB  20.8KB/s  20.8KB/s   00:00
Checking integrity... done
[1/1] Installing the_silver_searcher-0.17... done

設定

.agignore の書き方です。

debug
release

使い方

grepackと同じ感覚で使用できます。

root@b0:/etc/ssh # ag Password
git: not found
ssh_config
26:#   PasswordAuthentication yes
 
sshd_config
74:#PasswordAuthentication no
75:#PermitEmptyPasswords no
93:# PasswordAuthentication.  Depending on your PAM configuration,
97:# PAM authentication, then enable this but set PasswordAuthentication

gitコマンドがないと git not found と表示されるので、gitをインストール(pkg install git)しましょう。

root@b0:/etc/ssh # ag Password
git: not found
ssh_config

関連項目




スポンサーリンク