• Stars
    star
    832
  • Rank 54,253 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A code search / replace tool

amber

Actions Status Crates.io codecov

amber is a code search and replace tool written by Rust. This tool is inspired by ack, ag, and other grep-like tools.

Features

Useful default settings

  • Recursively search from the current directory
  • Ignore VCS directories (.git, .hg, .svn, .bzr)
  • Ignore binary files
  • Output by the colored format

Multi-threaded searching

Large files ( > 1MB by default) are divided and searched in parallel.

Interactive replacing

amber can replace a keyword over directories (traditionally by find ... | xargs sed -i '...') . You can decide to do replacing or not interactively.

Installation

Arch Linux

Install the amber-search-git package from AUR.

yaourt -S amber-search-git

Cargo

You can install with cargo.

cargo install amber

Manual

Download from release page, and extract to the directory in PATH.

Usage

Two commands (ambs/ambr) are provided. ambs means "amber search", and ambr means "amber replace". The search keyword is not regular expression by default. If you want to use regular expression, add --regex.

ambs keyword                  // recursively search 'keyword' from the current directory.
ambs keyword path             // recursively search 'keyword' from 'path'.
ambr keyword replacement      // recursively search 'keyword' from the current directory, and replace to 'replacement' interactively.
ambr keyword replacement path // recursively search 'keyword' from 'path', and replace to 'replacement' interactively.

amber replace interactively by default. If the keyword is found, the following prompt is shown, and wait. If you input 'y', 'Y', 'Yes', the keyword is replaced. 'a', 'A', 'All' means replacing all keywords non-interactively.

Replace keyword? ( Yes[Y], No[N], All[A], Quit[Q] ):

If --regex option is enabled, regex captures can be used in replacement of ambr.

$ cat text.txt
aaa bbb
$ ambr --no-interactive --regex '(aaa) (?<pat>bbb)' '$1 $pat ${1} ${pat}' test.txt
$ cat text.txt
aaa bbb aaa bbb

Configuration

Default flags can be configured by ~/.ambs.toml and ~/.ambr.toml. Available entries and default values are below:

regex          = false
column         = false
row            = false
binary         = false
statistics     = false
skipped        = false
interactive    = true
recursive      = true
symlink        = true
color          = true
file           = true
skip_vcs       = true
skip_gitignore = true
fixed_order    = true
parent_ignore  = true

You can choose some entries to override like below:

column = true

Benchmark

Environment

  • CPU: Intel(R) Xeon(R) Gold 6134 CPU @ 3.20GHz
  • MEM: 1.5TB
  • OS : CentOS 7.5

Target Data

Pattern

  • pattern1( many files with many matches ) : 'EXPORT_SYMBOL_GPL' in source1
  • pattern2( many files with few matches ) : 'irq_bypass_register_producer' in source1
  • pattern3( a large file with many matches ) : 'ๆคœ็ดข็ตๆžœ' in source2
  • pattern4( a large file with few matches ) : '"Quick Search"' in source2

Comparison Tools

Benchmarking Tool

hyperfine with the following options.

  • --warmup 3: to load all data on memory.

Result

  • search ( compare_ambs.sh )
pattern amber ripgrep grep
1 212.8ms ( 139% ) 154.1ms ( 100% ) 685.2ms ( 448% )
2 199.7ms ( 132% ) 151.6ms ( 100% ) 678.7ms ( 448% )
3 1.068s ( 100% ) 4.642s ( 434% ) 3.869s ( 362% )
4 1.027s ( 100% ) 4.409s ( 429% ) 3.118s ( 304% )
  • replace ( compare_ambr.sh )
pattern amber fastmod find/sed
1 792.2ms ( 100% ) 1231ms ( 155% ) 155724ms ( 19657% )
2 418.1ms ( 119% ) 352.4ms ( 100% ) 157396ms ( 44663% )
3 18.390s ( 100% ) 74.282s ( 404% ) 639.740s ( 3479% )
4 17.777s ( 100% ) 74.204s ( 417% ) 625.756s ( 3520% )

More Repositories

1

procs

A modern replacement for ps written in Rust
Rust
4,930
star
2

svls

SystemVerilog language server
Rust
431
star
3

sv-parser

SystemVerilog parser library fully compliant with IEEE 1800-2017
Rust
385
star
4

svlint

SystemVerilog linter
Rust
297
star
5

veryl

Veryl: A Modern Hardware Description Language
Rust
226
star
6

ptags

A parallel universal-ctags wrapper for git repository
Rust
123
star
7

D2dControl

WPF Control for Direct2D with SharpDX
C#
82
star
8

termbg

A Rust library for terminal background color detection
Rust
77
star
9

pipecolor

A terminal filter to colorize output
Rust
56
star
10

nom-tracable

Extension of nom to trace parser
Rust
48
star
11

prosafe_exporter

Prometheus exporter for NETGEAR switches supported by ProSAFE Plus utility
Rust
44
star
12

gip

a command-line tool to get global IP address
Rust
33
star
13

softether_exporter

Prometheus Exporter of SoftEther VPN Server
Rust
31
star
14

cargo-trend

Cargo subcommand to generate trend graph of dependent crates
Rust
28
star
15

flexlint

A flexible linter with rules defined by regular expression
Rust
28
star
16

structopt-toml

An default value loader from TOML for structopt
Rust
28
star
17

svls-vscode

SystemVerilog language server client for Visual Studio Code
TypeScript
21
star
18

nom-packrat

Extension of nom to apply "Packrat Parsing"
Rust
21
star
19

fts-rs

A Rust library for high performance directory walking using libc fts.
Rust
18
star
20

nom-recursive

Extension of nom to handle left recursion
Rust
16
star
21

mdbook-transcheck

Checker for translated mdbook
Rust
16
star
22

git-skel

A git subcommand to apply skeleton repository continuously
Rust
12
star
23

sdc-parser

Rust
11
star
24

nom-greedyerror

Custom error type of nom to improve accuracy of error position
Rust
10
star
25

sdcx

Rust
9
star
26

softfloat-wrapper

a safe wrapper of Berkeley SoftFloat based on softfloat-sys
Rust
9
star
27

svlint-action

SystemVerilog
7
star
28

vseq.vim

A Vim plugin for generating sequential number vertically
Vim Script
5
star
29

bitpattern

bitwise pattern matching and extracting
Rust
5
star
30

proc-reader

A std::io::Read implementation for stdout/stderr of other process
Rust
5
star
31

sample-rs

Rust
4
star
32

NeovimClient

Neovim msgpack-rpc Client by C#
C#
4
star
33

svlint-plugin-sample

A sample project of svlint plugin
Rust
4
star
34

rust-plugin-sample

Rust
4
star
35

softfloat_bench

Rust softfloat libarary benchmark
Rust
4
star
36

sv4state

Rust
3
star
37

rust-dpi-sample

SystemVerilog
3
star
38

rustified

Rust
2
star
39

veryl.vim

Vim Script
2
star
40

cc-version

gcc version detection for build.rs
Rust
2
star
41

custom_attribute_sample

Rust
2
star
42

dotfiles

Vim Script
2
star
43

bsd-kvm

Rust
1
star
44

rust-i586

rust-lang build environment for i586
Shell
1
star