Crates.io | amber |
lib.rs | amber |
version | 0.6.0 |
source | src |
created_at | 2016-02-07 16:13:18.761346 |
updated_at | 2023-12-27 07:45:32.543692 |
description | A code search and replace tool |
homepage | |
repository | https://github.com/dalance/amber |
max_upload_size | |
id | 4118 |
size | 181,291 |
amber is a code search and replace tool written by Rust. This tool is inspired by ack, ag, and other grep-like tools.
Large files ( > 1MB by default) are divided and searched in parallel.
amber can replace a keyword over directories (traditionally by find ... | xargs sed -i '...'
) .
You can decide to do replacing or not interactively.
Install the amber-search-git
package from AUR.
yaourt -S amber-search-git
You can install with cargo.
cargo install amber
Download from release page, and extract to the directory in PATH.
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
You can change configuration by writing a configuration file. The locations of the configuration file is OS-specific:
~/.config/amber/ambs.toml
, /etc/amber/ambs.toml
~/Library/Preferences/com.github.dalance.amber/ambs.toml
, /etc/amber/ambs.toml
~/AppData/Roaming/dalance/amber/config/ambs.toml
For compatibility, if ~/.ambs.toml
exists, it will be preferred to
the OS-specific locations.
The above paths are examples for the configuration of ambs
command.
ambr.toml
in the same directory is used for ambr
command.
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
line_by_match = false
You can choose some entries to override like below:
column = true
hyperfine with the following options.
--warmup 3
: to load all data on memory.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% ) |
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% ) |