All Projects → chinanf-boy → ripgrep-zh

chinanf-boy / ripgrep-zh

Licence: other
中文翻译:<BurntSushi/ripgrep> 一个面向行的搜索工具 ❤️ 校对 ✅

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to ripgrep-zh

V-zh
中文翻译:<vlang-io/V> V 编程语言(未发布,但从数据看,值得了解一下) ❤️ ❤️
Stars: ✭ 12 (-85.37%)
Mutual labels:  docs, zh
tokei-zh
🇨🇳翻译: <tokei> 代码信息的统计程序 ❤️ 校对 ✅
Stars: ✭ 92 (+12.2%)
Mutual labels:  docs, zh
mdBook-zh
中文翻译:<mdBook> 一个从 Markdown 文件创建现代在线书籍的实用程序 ❤️ 更新 ✅ 2022-1-8
Stars: ✭ 24 (-70.73%)
Mutual labels:  docs, zh
bat-zh
🇨🇳翻译: <bat> 一个`cat(1)`克隆与语法高亮和Git集成 ❤️ 校对 ✅
Stars: ✭ 129 (+57.32%)
Mutual labels:  docs, zh
SportsPage
运动页,一个基于社交的体育类APP
Stars: ✭ 30 (-63.41%)
Mutual labels:  docs
sphinx rtd dark mode
Adds a toggleable dark mode to the Read the Docs theme for Sphinx.
Stars: ✭ 29 (-64.63%)
Mutual labels:  docs
vtex-cms-sauce
VTEX package for handling CMS requests.
Stars: ✭ 25 (-69.51%)
Mutual labels:  files
glob-fs
file globbing for node.js. speedy and powerful alternative to node-glob. This library is experimental and does not work on windows!
Stars: ✭ 54 (-34.15%)
Mutual labels:  files
readonlyrest-docs
Official Documentation of ReadonlyREST Plugin
Stars: ✭ 77 (-6.1%)
Mutual labels:  docs
docs
Altinn documentation.
Stars: ✭ 17 (-79.27%)
Mutual labels:  docs
vsc-material-theme-icons
Material Theme Icons, the most epic icons theme for Visual Studio Code and Material Theme.
Stars: ✭ 90 (+9.76%)
Mutual labels:  files
FileOrganizer
Automatically organizes files in your computer
Stars: ✭ 34 (-58.54%)
Mutual labels:  files
huddle-apis
Documentation for the Huddle API
Stars: ✭ 17 (-79.27%)
Mutual labels:  docs
file2html
JS convertor of files to HTML and CSS code
Stars: ✭ 29 (-64.63%)
Mutual labels:  files
metadoc.js
Generates JSON metadata for Object Oriented JavaScript libraries. Used as a source for generating documentation.
Stars: ✭ 20 (-75.61%)
Mutual labels:  docs
api-doc
自动化文档生成工具
Stars: ✭ 13 (-84.15%)
Mutual labels:  docs
tg-file-decoder
Decode Telegram bot API file IDs
Stars: ✭ 30 (-63.41%)
Mutual labels:  files
upload
How to Upload a File to a Server in PHP
Stars: ✭ 83 (+1.22%)
Mutual labels:  files
fliegdoc
A documentation generator for Typescript-based libraries with good support for monorepos
Stars: ✭ 24 (-70.73%)
Mutual labels:  docs
allure-docs
Allure Framework documentation
Stars: ✭ 50 (-39.02%)
Mutual labels:  docs

BurntSushi/ripgrep translate-svg

「 ripgrep 是一个面向行的搜索工具 」

中文 | english


更新

翻译的原文 与日期 最新更新 更多
commit 2019-04-14 last 中文翻译

贡献

欢迎 👏 勘误/校对/更新贡献 😊 具体贡献请看

生活

If help, buy me coffee —— 营养跟不上了,给我来瓶营养快线吧! 💰


ripgrep (rg)

ripgrep 是一个面向行的搜索工具,它在遵循 gitignore 规则的同时,递归地搜索当前目录以寻找正则表达式模式。ripgrep 在 Windows、MaCOS 和 Linux 上拥有一流的支持,可以下载并使用每个 release二进制文件。 ripgrep 类似于其他流行的搜索工具,如 ag,ACK 和 grep。

Linux build status Windows build status Crates.io

MIT 或 UNLICENSE的双重许可。

CHANGELOG

请看CHANGELOG发布历史 - english

文档快速链接

搜索结果快照

A screenshot of a sample search with ripgrep

各大工具对比例子

此示例搜索整个 Linux 内核源树(运行make defconfig && make -j8后),找寻匹配项为[A-Z]+_SUSPEND,所有匹配必须是单词。在具有 Intel i7-6900K 3.2GHz 的系统上统计时间,并在启用 SIMD 的情况下编译 ripgrep。

请记住,单一的基准是不够的! 看到我博客上关于 ripgrep 的博文,其有更多的基准和分析进行了非常详细的比较.

工具 命令 行计数 时间
ripgrep(Unicode) rg -n -w '[A-Z]+_SUSPEND' 450 0.106s
git grep LC_ALL=C git grep -E -n -w '[A-Z]+_SUSPEND' 450 0.55
The Silver Searcher ag -w '[A-Z]+_SUSPEND' 450 0.895
git grep (Unicode) LC_ALL=en_US.UTF-8 git grep -E -n -w '[A-Z]+_SUSPEND' 450 2.266s
sift sift --git -n -w '[A-Z]+_SUSPEND' 450 3.505s
ack ack -w '[A-Z]+_SUSPEND' 一千八百七十八 6.823s
The Platinum Searcher pt -w -e '[A-Z]+_SUSPEND' 450 14.208s

(是的,ack 会有个bug)

这是另一个忽略 gitignore 文件和用白名单搜索的基准。语料库与前面的基准测试相同,传递给每个命令的相同标志,确保它们正在执行相同的工作:

工具 命令 行计数 时间
ripgrep rg -L -u -tc -n -w '[A-Z]+_SUSPEND' 404 0.079s
ucg ucg --type=cc -w '[A-Z]+_SUSPEND' 390 0.163s
GNU grep egrep -R -n --include='*.c' --include='*.h' -w '[A-Z]+_SUSPEND' 404 0.611s

(ucg 在存在符号链接时,行为略有不同)

最后,在一个单一的大文件(~9.3GB)上,ripgrep 和 GNU grep 之间的直接比较。OpenSubtitles2016.raw.en.gz:

工具 命令 线路计数 时间
ripgrep rg -w 'Sherlock [A-Z]\w+' 5268 2.108s
GNU grep LC_ALL=C egrep -w 'Sherlock [A-Z]\w+' 5268 7.014s

在上述基准中,传递-n标志(用于显示行号),会增加时间,2.640s的 ripgrep 和10.277s的 GNU grep.

为什么我应该使用 ripgrep?

  • 它可以替换由其他搜索工具提供的许多用例,因为它包含它们的大部分特性,并且通常更快。(见FAQ有关 ripgrep 是否能够真正取代 grep 的更多细节。
  • 像其他专门用于代码搜索的工具一样,ripgrep 默认用于递归目录搜索,并且不会搜索被.gitignore匹配的文件/+夹。默认情况下,它也忽略了隐藏文件和二进制文件。ripgrep 还实现了对.gitignore支持,然而,在其它代码搜索工具中,有许多与该功能相关的 bug 工具,声称提供了相同的功能。
  • ripgrep 可以搜索特定类型的文件。例如,rg -tpy foo将搜索限制为 Python 文件,rg -Tjs foo从搜索中排除 JavaScript 文件 。ripgrep 可以用自定义匹配规则教给新的文件类型。
  • ripgrep 支持许多grep特性。例如,显示搜索结果的上下文、搜索多个模式、突出显示具有颜色和全部 Unicode 支持的匹配与 GNU grep 不同,ripgrep 在支持 Unicode(总是在 启动)的同时保持快速。
  • ripgrep 有可选的支持,以切换其正则表达式引擎使用 PCRE2 。除此之外,这使得在模式中,使用环视和反向引用成为可能,而这些在 ripgrep 的默认正则表达式引擎中不受支持。启用 PCRE2 支持用-P
  • ripgrep 支持以 UTF-8 以外的文本编码搜索文件,例如 UTF-16, latin-1, GBK, EUC-JP, Shift_JIS 等等。提供了自动检测 UTF 16 的一些支持。其他文本编码必须与-E/--encoding参数搭配使用)
  • ripgrep 支持搜索通用格式(gzip、xz、lzma、bzip2 或 lz4)的压缩文件,搭配-z/--search-zip参数.
  • ripgrep 支持任意的输入预处理过滤器,这些过滤器可以是 PDF 文本提取、较少支持的解压缩、解密、自动编码检测等。

换句话说,如果你喜欢速度,默认的过滤,更少的 bug 和 Unicode 支持,使用 ripgrep。

为什么我不用 ripgrep?

尽管最初不希望将每个特性都添加到 ripgrep 中,但是随着时间的推移,ripgrep 对其他文件搜索工具中的大多数特性的支持不断增加。这包括搜索跨越多行的结果,以及对 PCRE2 的 opt-in 支持,PCRE2 提供环视和反引号支持。

译者: 环视: 在知乎找了个说明文

此时,不使用 ripgrep 的主要原因可能包括以下一个或多个:

  • 你需要一个便携的无所不在的工具。尽管 ripgrep 在 Windows、macOS 和 Linux 上工作,但它并不普遍,也不符合 POSIX 等任何标准.做这项工作最好的工具是老 grep。
  • 在这个 README 中仍然有一些您心目中所依赖的其他特性(或 bug)没有列出,这些东东在其他工具中,而不在 ripgrep 。
  • 有一个性能边缘情况,ripgrep 做得不好(而在其他工具做得好的地方)。(请提交 bug 报告!)
  • ripgrep 不可能安装在您的机器上,或者不适用于您的平台.(请提交 bug 报告!)

真的超越所有?

一般来说,是的。大量的基准,每一个都有详细的分析.尽在我的博客上.

总之,ripgrep 很快,因为:

  • 它建在Rust's regex 引擎。 Rust 的正则表达式引擎使用有限自动机、SIMD 和积极的文字优化来使搜索非常快。(PCRE2 支持可以与-P/--PCRE2参数)
  • Rust 的 regex 库通过将 UTF-8 解码直接构建到其确定性有限自动机引擎中,从而在完全 Unicode 支持下,保持性能。
  • 它支持使用内存映射,或通过使用中间缓冲区递增地搜索进行搜索。前者对于单个文件更好,后者对于大目录更好。ripgrep 自动为您选择最佳搜索策略。
  • 将您的.gitignore文件的忽略模式,应用了一个RegexSet。 这意味着单个文件路径,可以同时匹配多个 glob 模式。
  • 它使用一个无锁的并行递归目录迭代器crossbeamignore

功能 比较

Andy Lester,ack作者已发布了一个比较 ack、ag、git-grep、GNU grep 和 ripgrep 特性的优秀表:https://beyondgrep.com/feature-comparison/

请注意,ripgrep 最近增加了一些尚未出现在 Andy 表中的重要新特性。这包括但不限于,配置文件、passthru、对搜索压缩文件的支持、多行搜索和通过 PCRE2 支持选择高级正则表达式。

Installation

  • 安装

ripgrep 的二进制名是rg

Windows,macOS 和 Linux 的 二进制文件,尽在于此,若以下有用户的平台没提到的,建议下载这些压缩中的一个。

Linux 二进制文件是静态可执行文件。Windows 二进制文件可用 MinGW(GNU)或微软 Visual C++(MSVC)构建。如果可能的话,更喜欢 MSVC 超过 GNU,但是你需要安装有Microsoft VC++ 2015 redistributable

如果你是macOS Homebrew或 一个Linuxbrew用户,然后可以从 homebrew-core 安装 ripgrep,(用 Rust 稳定版编译,没有 SIMD 支持):

$ brew install ripgrep

或者您可以通过使用定制的 tab 来安装,用 rust nightly 版本 编译的二进制文件(包括 SIMD 和所有优化):

$ brew tap burntsushi/ripgrep https://github.com/BurntSushi/ripgrep.git
$ brew install ripgrep-bin

如果你是MacPorts用户,然后可以从官方 ports下载 ripgrep:

$ sudo port install ripgrep

如果你是Windows Chocolatey用户,然后可以从官方 repo:

$ choco install ripgrep

如果你是Windows Scoop用户,然后可以从官方 bucket:

$ scoop install ripgrep

如果你是一个Arch Linux用户,然后您可以从官方,安装 ripgrep :

$ pacman -S ripgrep

如果你是 Gentoo 用户,可以从官方 repo:

$ emerge sys-apps/ripgrep

如果你是 Fedora 27 + 用户,可以从官方存储库安装 ripgrep.

$ sudo dnf install ripgrep

如果你是 Fedora 24 + 用户,可以从copr安装 ripgrep:

$ sudo dnf copr enable carlwgeorge/ripgrep
$ sudo dnf install ripgrep

如果你是一个openSUSE Tumbleweed用户,可以从官方 repo:

$ sudo zypper install ripgrep

如果你是RHEL/CentOS 7用户,可以从copr安装 ripgrep:

$ sudo yum-config-manager --add-repo=https://copr.fedorainfracloud.org/coprs/carlwgeorge/ripgrep/repo/epel-7/carlwgeorge-ripgrep-epel-7.repo
$ sudo yum install ripgrep

如果你是Nix用户,可以从nixpkgs安装 ripgrep:

$ nix-env --install ripgrep
$ # (Or using the attribute name, which is also ripgrep.)

如果你是Debian用户(或 Ubuntu 的用户),然后,可以使用每一个ripgrep release提供的二进制.deb文件来安装 ripgrep。

$ curl -LO https://github.com/BurntSushi/ripgrep/releases/download/0.10.0/ripgrep_0.10.0_amd64.deb
$ sudo dpkg -i ripgrep_0.10.0_amd64.deb

如果运行 Debian Buster(当前 Debian 测试)或 Debian SID,ripgrep 是Debian 官方包所具备的.

$ sudo apt-get install ripgrep

如果你是一个Ubuntu Cosmic(18.10)(或更新的)用户,ripgrep与上面相同,是可以使用与 Debian 包装:

$ sudo apt-get install ripgrep

(N.B.Ubuntu 上 ripgrep 的各种快照包也是可用的,但是它们似乎都不能正常工作,并且生成许多非常奇怪的 bug 报告,我不知道如何修复,也没有时间修复)。因此,它不再是推荐的安装选项

如果你是FreeBSD用户,然后可以从官方 ports安装:

# pkg install ripgrep

如果你是一个OpenBSD用户,然后可以从官方 ports安装:

$ doas pkg_add ripgrep

如果你是NetBSD用户,然后可以从pkgsrc安装 ripgrep:

# pkgin install ripgrep

如果你是Rust 程序员 可以用cargo安装 ripgrep.

  • 请注意,ripgrep 的最小 Rust 支持版本的是1.23.0,虽然 ripgrep 可能与旧版本一起工作。
  • 请注意,二进制可能大于预期,因为它包含调试符号。这是故意的。若要删除调试符号,并减少文件大小,请运行二进制的strip
$ cargo install ripgrep

当使用 Rust 1.27 或更新版本进行编译时,这将自动启用搜索的 SIMD 优化。

ripgrep 目前不在任何其他包库中。我更喜欢这样.

Building

  • 构建

ripgrep 是用 Rust 编写的,所以你需要先具有一个Rust。ripgrep 与 Rust 1.28.0(稳定)或打上。一般来说,ripgrep 会跟随 Rust 编译器的最新稳定版本.

构建 ripgrep:

$ git clone https://github.com/BurntSushi/ripgrep
$ cd ripgrep
$ cargo build --release
$ ./target/release/rg --version
0.1.3

如果您有一个 Rust 夜间(nightly)编译器和最近的 Intel CPU,那么您可以启用额外的可选 SIMD 加速,如下所示:

RUSTFLAGS="-C target-cpu=native" cargo build --release --features 'simd-accel avx-accel'

如果您的机器不支持 AVX 指令,则只需从功能列表中删除avx-accel。SIMD 也类似(它大致对应于 SSE 指令)。

在某些 ripgrep 依赖项中,simd-accelavx-accel功能会支持 SIMD(负责计算行数和转码)。它们不需要获得 SIMD 优化搜索; 那些是自动启用。希望有一天,simd-accelavx-accel特征变得不必要。

最后,可选择加入 PCRE2 的支持,此为通过启用PCRE2功能参与 ripgrep 的构建:

$ cargo build --release --features 'PCRE2'

(提示:使用--features 'PCRE2 simd-accel avx-accel'还包括编译时 SIMD 优化,这将只适用于夜间编译器。

启用 PCRE2 特性可以与稳定的 Rust 编译器一起工作,并将尝试通过pkg-config自动查找,并链接到系统的 PCRE2 库。 如果不存在,那么 ripgrep 将使用系统的 C 编译器,从源代码构建 PCRE2,然后静态地将其链接到最终的可执行文件中。即使存在可用的 PCRE2 系统库,也可以通过构建具有 MUSL 目标的 ripgrep ,或通过设置强制静态链接PCRE2_SYS_STATIC=1

在 Linux 上,能以 MUSL 为目标,构建 ripgrep ,通过在您的系统上先安装 MUSL 库(咨询您友好的邻居 - 包管理器)。然后,您只需要将 MUSL 支持,添加到 Rust 工具链,并重新构建 ripgrep,它就会生成一个完全静态的可执行文件:

$ rustup target add x86_64-unknown-linux-musl
$ cargo build --release --target x86_64-unknown-linux-musl

应用上面的--features参数,就会如愿以偿。如果您想用 MUSL 和 PCRE2 构建静态可执行文件,那么您将需要已安装musl-gcc,它可能位于与实际 MUSL 库分隔的包中,这取决于您的 Linux 发行版。

Running tests

  • 运行测试

ripgrep 的测试相对不错,包括单元测试和集成测试。若要运行完整的测试套件,请使用:

$ cargo test --all

位于存储库的根目录。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].