the_silver_searcher README

The project's README from github.com/ggreer/the_silver_searcher. As one markdown file: README.md.

The Silver Searcher

A code searching tool similar to ack, with a focus on speed.

Build Status

Floobits Status

#ag on Freenode

Do you know C? Want to improve ag? I invite you to pair with me.

What's so great about Ag?

Ag is quite stable now. Most changes are new features, minor bug fixes, or performance improvements. It's much faster than Ack in my benchmarks:

ack test_blah ~/code/  104.66s user 4.82s system 99% cpu 1:50.03 total

ag test_blah ~/code/  4.67s user 4.58s system 286% cpu 3.227 total

Ack and Ag found the same results, but Ag was 34x faster (3.2 seconds vs 110 seconds). My ~/code directory is about 8GB. Thanks to git/hg/ignore, Ag only searched 700MB of that.

There are also graphs of performance across releases.

How is it so fast?

I've written several blog posts showing how I've improved performance. These include how I added pthreads, wrote my own scandir(), benchmarked every revision to find performance regressions, and profiled with gprof and Valgrind.

Installing

macOS

brew install the_silver_searcher

or

port install the_silver_searcher

Linux

BSD

Windows

Building from source

Building master

  1. Install dependencies (Automake, pkg-config, PCRE, LZMA):

    • macOS:

        brew install automake pkg-config pcre xz
      

      or

        port install automake pkgconfig pcre xz
      
    • Ubuntu/Debian:

        apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev
      
    • Fedora:

        yum -y install pkgconfig automake gcc zlib-devel pcre-devel xz-devel
      
    • CentOS:

        yum -y groupinstall "Development Tools"
        yum -y install pcre-devel xz-devel zlib-devel
      
    • openSUSE:

        zypper source-install --build-deps-only the_silver_searcher
      
    • Windows: It's complicated. See this wiki page.

  2. Run the build script (which just runs aclocal, automake, etc):

     ./build.sh
    

    On Windows (inside an msys/MinGW shell):

     make -f Makefile.w32
    
  3. Make install:

     sudo make install
    

Building a release tarball

GPG-signed releases are available here.

Building release tarballs requires the same dependencies, except for automake and pkg-config. Once you've installed the dependencies, just run:

./configure
make
make install

You may need to use sudo or run as root for the make install.

Editor Integration

Vim

You can use Ag with ack.vim by adding the following line to your .vimrc:

let g:ackprg = 'ag --nogroup --nocolor --column'

or:

let g:ackprg = 'ag --vimgrep'

Which has the same effect but will report every match on the line.

Emacs

You can use ag.el as an Emacs front-end to Ag. See also: helm-ag.

TextMate

TextMate users can use Ag with my fork of the popular AckMate plugin, which lets you use both Ack and Ag for searching. If you already have AckMate you just want to replace Ack with Ag, move or delete "~/Library/Application Support/TextMate/PlugIns/AckMate.tmplugin/Contents/Resources/ackmate_ack" and run ln -s /usr/local/bin/ag "~/Library/Application Support/TextMate/PlugIns/AckMate.tmplugin/Contents/Resources/ackmate_ack"

Other stuff you might like

the_silver_searcher (ggreer/the_silver_searcher)

Searching Database…

这是什么?The Silver Searcher(ag)是一款命令行代码搜索工具,功能类似 ack,主打速度快。
这是 grep 的替代品,还是别的东西?它是一款类似 grep/ack 的文本搜索工具,专门用于搜索源代码:会自动跳过 .gitignore 和 .hgignore 中忽略的文件,还可以通过 .ignore 文件添加额外的忽略规则。
如何安装 ag?使用你所在平台的包管理器:macOS 上运行 'brew install thesilversearcher',Ubuntu/Debian 上运行 'apt-get install silversearcher-ag',Arch 上运行 'pacman -S thesilversearcher',Windows 上运行 'winget install "The Silver Searcher"' 或使用 Chocolatey 安装。也可以用 ./build.sh 从源代码编译,然后执行 sudo make install。
Windows 版本是官方维护的吗?Windows 支持依赖非官方的每日构建版本,以及 winget、Chocolatey、MSYS2、Cygwin 等软件包,而且据介绍,在 Windows 上从源代码编译比较复杂。
除了 Linux 和 macOS,它也支持 BSD 吗?支持。FreeBSD 以及 OpenBSD/NetBSD 都有专门的安装说明,分别通过 pkg install 或 pkgadd 安装。
ag 为什么比 ack 快?它使用 Pthreads 在多个 CPU 核心上并行搜索文件,用 mmap() 映射文件,而不是把文件读入缓冲区;字面量搜索使用 Boyer-Moore strstr 算法;正则搜索则利用 PCRE 的 JIT 编译器(需在使用 PCRE >=8.21 编译时启用)。
在实际使用中,ag 比 ack 快多少?作者在一个 8GB 的代码目录上做过基准测试:ag 比 ack 快约 34 倍(3.2 秒对 110 秒)。
我可以在 Vim 或 Emacs 中使用 ag 吗?可以。Vim 用户可以通过 g:ackprg 设置把 ag 接入 ack.vim;Emacs 用户可以使用 ag.el 或 helm-ag 前端。
我应该用 ag,还是 ripgrep/git-grep 之类的工具?README 本身列出了一些相关工具供你比较,包括 Git-grep(同样快,但只能用于 git 仓库)、Exuberant Ctags(更快,但需要预先构建索引)、ripgrep,以及 Sack(对 Ack 和 Ag 的封装)。
What are similar projects?fff, numba, zenc, ripgrep, fzf.vim, neomacs, fzf, nnn
Which topics is it in?fzf, grep, emacs, speed, code-search, jit, parallel, vim, search, bsd, c, performance
Creator
ggreer
Size
2.4 MB
Stars
27.1K
Updated
CommitDec 17
Age
14y
Commits · 90 Days