amber is a code search and replace tool written by Rust

amber is a code search and replace tool written by ack,

amber

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.

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.

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.

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

Configuration

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

You can choose some entries to override like below:

Benchmark

Environment

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

Target Data

  • source1: https://github.com/torvalds/linux ( 52998files, 2.2GB )
  • source2: https://dumps.wikimedia.org/jawiki/latest/jawiki-latest-pages-articles.xml.bz2 ( 1file, 8.5GB )

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

  • amber (v0.5.1)
  • ripgrep (v0.10.0)
  • grep (v2.20)
  • fastmod (v0.2.0)
  • find/sed (v4.5.11/v4.2.2)

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% )
Issues

Collection of the latest Issues

Miserlou

Miserlou

0

I have a lot of things to template, so I use Amber in a script. Every time, Amber wants to replace the values found in that script which is currently telling amber to replace those values, so I have to be very careful not to ruin my script!

It'd be create that if amber could detect if, for instance, it is being called by /foo/bar/create_template.sh then /foo/bar/create_template.sh would be omitted from the list of files to be replaced.

Related to https://github.com/dalance/amber/issues/47

golddranks

golddranks

2

It would be helpful if amber provided also support for renaming files.

There is a common tool called rename (from the linux-utils package), but it doesn't support regex.

On the other hand, simply doing a for loop in bash is error prone (non-interactive & requires working bash knowledge) and doesn't support recursion.

Thus, I think that it would be a nice functionality for amber to provide. Any chances?

No3371

No3371

0

Example

Issues

  1. ^ 1. 「(.+)\n(?! 2.) expected to work but failed to match, does amber support Negative Look Ahead?
  2. ^ 1. 「(.+)\n matching works but replacing does not, it failed to capture. >「$1 replacement result:

    Expected: 1. 「ことの葉は強 (こは) く見ゆれどすまひ草露には―・つるものにざりける」〈[源順集](https://dictionary.goo.ne.jp/word/person/%E6%BA%90%E9%A0%86/#jn-212920)〉 Returned: > 1. 「

  3. As other have reported, amber does not support \n in replacement string.
EricCrosson

EricCrosson

0

Use case:

Sometimes I want to do an ambitious search or search/replace but I get a bunch of junk files I don't want to touch, like a CHANGELOG.md or a package-lock.json.

It would be nice to add an argument to ambs/ambr to ignore these files, e.g.

and

The current workarounds I've been using are grep -v and trying to manually select 'no' on the replace query for the files I don't want to replace text inside. I can assure you, this is a very error prone process :sweat_smile:

jtrakk

jtrakk

0

The Freedesktop standard has an environment variable XDG_CONFIG_DIRS which sets the location for config directories. On Linux for example it's usually under ~/.config/. It's nice to keep all the config files in one place and avoid cluttering the home dir.

ryuheechul

ryuheechul

0

Amber gives a lot of option to ignore things for different use cases which is great. However it also comes with cost that there is a high chance that amber will run differently on different environments. And that could become hard to debug what things are being ignored and why.

In my use case is that running amber on Github Actions and somehow the target files being ignored and I just can't find why and the nature of Github Actions makes it hard to debug. Which is not a scope for Amber of course but I think having verbose option to see what amber is processing and skipping or ignoring and why would be awesome nonetheless.

Boscop

Boscop

1

In msys it doesn't react to entering y. Instead, I have to Ctrl-C and then it tries to execute y on the shell.

Boscop

Boscop

0

How to specify the number of surrounding lines to show as context with ambr? For making better replacing decisions.

EDIT: It doesn't seem to have that option, at least according to -h. I suggest adding this option with -c <N> / --context <N> It would also be useful for ambs.

Suggestion: If the number is specified with a plus (+) sign in front, only show N following lines, none behind.

hassek

hassek

2

sometimes, instead of wanting to replace a text with another, I want to delete the entire line of a matched value. Adding support to this would be great!

dalance

dalance

0
  • .gitignore search to lower directory
  • .gitignore search to upper directory
  • ! support
  • ** support
Versions

Find the latest versions by id

v0.5.9 - Apr 06, 2021

v0.5.8 - Nov 22, 2020

v0.5.7 - Nov 22, 2020

v0.5.6 - Nov 22, 2020

v0.5.5 - Nov 04, 2020

v0.5.4 - Apr 11, 2020

v0.5.3 - Nov 20, 2019

v0.5.2 - May 01, 2019

v0.5.1 - Sep 11, 2018

v0.5.0 - Sep 10, 2018

v0.4.6 - Jun 18, 2018

v0.4.5 - Jun 14, 2018

v0.4.4 - Jun 14, 2018

v0.4.3 - May 16, 2018

v0.4.1 - May 16, 2018

v0.3.3 - Feb 28, 2017

v0.3.0 - Jun 13, 2016

v0.2.3 - Mar 04, 2016

v0.2.2 - Feb 26, 2016

v0.2.1 - Feb 24, 2016

v0.2.0 - Feb 05, 2016

v0.1.6 - Jan 24, 2016

v0.1.5 - Jan 23, 2016

v0.1.4 - Jan 23, 2016

v0.1.3 - Jan 23, 2016

v0.1.2 - Jan 23, 2016

v0.1.1 - Jan 23, 2016

v0.1.0 - Jan 23, 2016

Information - Updated May 13, 2022

Stars: 320
Forks: 10
Issues: 19

Repositories & Extras

An open source Gameboy emulator written in Rust that can use a command line interface...

An open source Gameboy emulator written in Rust that can use a command line interface as a screen and input device

An open source Gameboy emulator written in Rust that can use a command line interface...

gip is a command-line tool and Rust library to check global IP address

Currently built-in service providers are the followings

gip is a command-line tool and Rust library to check global IP address
CLI

317

electron-hardener

A Rust library and command line tool to harden Electron binaries against runtime behavior modifications

electron-hardener

This is the repository of CLI commands written in Rust, it is for my practices

This repository contains the following commands (Typical commands in UNIX)

This is the repository of CLI commands written in Rust, it is for my practices

This is a Rust command line tool that calculates a histogram of the separate types...

This is a Rust command line tool that calculates a histogram of the separate types of JSON records in an input JSON log file (one...

This is a Rust command line tool that calculates a histogram of the separate types...

cmsis-pack-manager

is a python module, Rust crate and command line utility for managing current device information that is stored in many CMSIS PACKs

cmsis-pack-manager

Find all your notes with one command!

Todo_r is a simple rust command line utility that keeps track of your todo items in code

Find all your notes with one command!

First, complete the basic Rust setup instructions

Use Rust's native cargo command to build and launch the template node:

First, complete the basic Rust setup instructions
Facebook Instagram Twitter GitHub Dribbble
Privacy