[HN Gopher] Amber: A code search and replace tool
___________________________________________________________________
Amber: A code search and replace tool
Author : bpierre
Score : 77 points
Date : 2024-05-23 14:48 UTC (8 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| laerus wrote:
| At this rate of naming projects after the same valuable stones,
| we are going to need namespacing for the CLI tools.
| ape4 wrote:
| Use amber to search through your amber code
| tazjin wrote:
| This project has been around for a while.
| ecshafer wrote:
| Off the top of my head amber can refer to: an in browser small
| talk implementation, a typed to bash compiled language, a text
| replacement tool, a crystal mvc web framework, and a medical
| simulation software.
| wormius wrote:
| Dang I made my post and now I see I really do need a heart
| attack, I only knew the first 3, and now you throw two more
| in the mix. Yikes.
| slimsag wrote:
| related, you might want to consider changing your username -
| when I saw your comment I thought you were the Madrid sporting
| organization and it took me a while to realize.
| pizzafeelsright wrote:
| Amber is the ex who keeps digging up the past.
| wormius wrote:
| There's an Amber Smalltalk and Amber Bash Scripting Language
| and this. I just discovered these literally the past week.
|
| "Namespace collisions" in the real world get my goat in
| general, but in this case, I'm about to have a heart attack
| from the discovery of all 3 in one week.
|
| I get why for all cases : amber=electron/elektro in Ancient
| Greek.* But still.
|
| * One of my favorite albums is Amber by Autechre, and where I
| learned this nugget (also - it's a pile of Sand Dunes on the
| cover, so silicon). Clever boys.
| danilonc wrote:
| Reminded me of https://github.com/ast-grep/ast-grep and I wonder
| how it compares in performance and functionality.
| danilonc wrote:
| ast-grep find/replace Abstract Syntax Tree. Amber matches on
| regex.
|
| It seems ast-grep is more powerful if you don't exactly know
| how the code is structured.
| eviks wrote:
| This used the more sound approach of treating code as code
| herrington_d wrote:
| ast-grep is based on tree-sitter parsers and most of the time
| is spent on parsing.
|
| There is some optimization to [skip
| parsing](https://github.com/ast-grep/ast-
| grep/blob/9f8ed5fb2abf35d928...) but generally I don't expect
| ast-grep can beat ripgrep or amber. (but sometimes ast-grep can
| beat grep due to parallel processing)
| mcepl wrote:
| https://github.com/BurntSushi/ripgrep ???
| zsyllepsis wrote:
| The author specifically mentions, and benchmarks against,
| ripgrep in the linked content.
| kstrauser wrote:
| Ripgrep lacks the "& replace" bit.
| cess11 wrote:
| Nah. $ rg 'sear' -r 'repl' file.txt
| burntsushi wrote:
| That only replaces in the output. ambr seems to actually
| modify the file contents, like `sed -i`. ripgrep never
| modifies the contents of files.
| cess11 wrote:
| Right, can use --passthru and > or sponge to write it to
| disk.
|
| Edit: Oh, it's you. Thanks for a brilliant tool, I use it
| every workday and have been for years.
| VagabundoP wrote:
| https://news.ycombinator.com/item?id=40431835
|
| EDIT: Opps same name different project.
| jes5199 wrote:
| I'm glad that people make tools like this, but this is a task
| that I need to do so rarely that I'm likely to forget it exists,
| which means that I'll likely roll my own (inferior!) version as a
| one-time thing.
| Ringz wrote:
| Is it possible to store my config files under ~.config/amber/ on
| MacOS?
| saurik wrote:
| I don't understand what makes this a "code" search and replace
| tool as opposed to a general text search and replace tool (a la
| the many many existing options for such). I was kind of expecting
| some kind of AST structure or grammar spec or at least a quick
| tokenizer to be able to handle situations like "don't replace
| this text if it appears in a string constant", but it doesn't
| mention anything like that.
| zeroxfe wrote:
| Even without a grammar spec, there's lots of things common in
| _most_ languages: quoted strings, whitespaces, matching
| braces/parens, etc.
| alexpovel wrote:
| The tool you are describing is what I am trying to build at
| https://github.com/alexpovel/srgn . The idea is a compromise
| between regex (think ripgrep) and grammar awareness (through
| tree-sitter).
| herrington_d wrote:
| Hey! ast-grep author here. I believe what you want is probably
| what https://github.com/ast-grep/ast-grep can help you.
|
| More specifically for the "string constant" search/replace, you
| can see the playground example!
|
| https://ast-grep.github.io/playground.html#eyJtb2RlIjoiUGF0Y...
| dmix wrote:
| I used to use https://comby.dev/ which is amazing when it works
| but I kept having issues where it wouldn't accept my input or
| it'd error during processing. It was very flaky. So I've resorted
| to using https://github.com/piranha/goreplace as backup which is
| much simpler but reliable.
|
| I'll check this one out...
| PaulDavisThe1st wrote:
| find . [ ... find args ] | sed -e 's/nee\(dl[aeiou]\)/stack\1/g'
| Singletoned wrote:
| Can it do multiline search and replace?
| malthejorgensen wrote:
| Feels similar to `sd` (https://github.com/chmln/sd)
|
| which in my mind was the first "replace" version of ripgrep
|
| grep -> ripgrep
|
| sed -> sd
| sam0x17 wrote:
| not to be confused with Amber, the crystal lang web framework
| replwoacause wrote:
| Or Amber, the programming language that compiles to Bash,
| posted here just the other day.
| js2 wrote:
| [delayed]
___________________________________________________________________
(page generated 2024-05-23 23:00 UTC)