首页
/ The Silver Searcher 技术文档

The Silver Searcher 技术文档

2024-12-20 09:19:33作者:韦蓉瑛

The Silver Searcher(简称 Ag)是一个快速的代码搜索工具,类似于 ack,但速度更快。以下为 Ag 的安装指南、使用说明以及 API 使用文档。

1. 安装指南

macOS

使用 Homebrew 或 MacPorts 安装:

brew install the_silver_searcher

port install the_silver_searcher

Linux

根据不同的发行版,安装方式有所不同:

  • Ubuntu >= 13.10 (Saucy) 或 Debian >= 8 (Jessie)

    apt-get install silversearcher-ag
    
  • Fedora 21 及以下版本

    yum install the_silver_searcher
    
  • Fedora 22+

    dnf install the_silver_searcher
    
  • RHEL7+

    yum install epel-release.noarch the_silver_searcher
    
  • Gentoo

    emerge -a sys-apps/the_silver_searcher
    
  • Arch

    pacman -S the_silver_searcher
    
  • Slackware

    sbopkg -i the_silver_searcher
    
  • openSUSE

    zypper install the_silver_searcher
    
  • CentOS

    yum install the_silver_searcher
    
  • NixOS/Nix/Nixpkgs

    nix-env -iA silver-searcher
    
  • SUSE Linux Enterprise: 参考以下指南

BSD

  • FreeBSD

    pkg install the_silver_searcher
    
  • OpenBSD/NetBSD

    pkg_add the_silver_searcher
    

Windows

  • Win32/64: 不官方的每日构建版本在此处提供。

  • winget

    winget install "The Silver Searcher"
    
  • Chocolatey

    choco install ag
    
  • MSYS2

    pacman -S mingw-w64-{i686,x86_64}-ag
    
  • Cygwin: 运行相关的 setup-*.exe 文件,并在 "Utils" 类别中选择 "the_silver_searcher"。

2. 项目使用说明

Ag 的使用非常简单,可以通过命令行调用。例如,搜索包含 "test_blah" 字符串的文件:

ag test_blah ~/code/

Ag 会忽略 .gitignore.hgignore 文件中的文件模式,也可以通过 .ignore 文件添加额外的忽略模式。

3. 项目 API 使用文档

Ag 没有官方的 API 文档,但是可以通过命令行参数进行调用和使用。以下是一些常用的命令行参数:

  • --nogroup: 不按文件分组显示结果。
  • --nocolor: 不使用颜色高亮显示结果。
  • --column: 显示匹配项的列号。

4. 项目安装方式

除了使用包管理器安装外,也可以从源代码构建:

从 master 分支构建

  1. 安装依赖(Automake、pkg-config、PCRE、LZMA):

    • macOS:

      brew install automake pkg-config 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: 构建 Windows 版本比较复杂,请参考 这个 wiki 页面

  2. 运行构建脚本:

    ./build.sh
    

    在 Windows(msys/MinGW shell)中:

    make -f Makefile.w32
    
  3. 安装:

    sudo make install
    

构建发布压缩包

发布版本的 GPG 签名压缩包可以在 这里 找到。构建发布压缩包需要相同的依赖,除了 Automake 和 pkg-config。安装依赖后,运行:

./configure
make
make install

可能需要使用 sudo 或以 root 用户运行 make install

登录后查看全文
热门项目推荐
相关项目推荐