40 comments

[ 2.6 ms ] story [ 98.6 ms ] thread
At this rate of naming projects after the same valuable stones, we are going to need namespacing for the CLI tools.
Use amber to search through your amber code
This project has been around for a while.
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.
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.
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.
but mine can be read backwards
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/ήλεκτρο 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.

Reminded me of https://github.com/ast-grep/ast-grep and I wonder how it compares in performance and functionality.
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.

This used the more sound approach of treating code as code
The author specifically mentions, and benchmarks against, ripgrep in the linked content.
Ripgrep lacks the “& replace” bit.
Nah.

   $ rg 'sear' -r 'repl' file.txt
That only replaces in the output. ambr seems to actually modify the file contents, like `sed -i`. ripgrep never modifies the contents of files.
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.

ripgrep is brilliant and I use it a lot but it has no knowledge of the languages it works with so I don't use it for searching anything more than names of functions or stuff.

If you really need to search for code constructs that can span multiple lines (but not always do) then Treesitter-aware tools like ast-grep and gritql are superior.

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.
Is it possible to store my config files under ~.config/amber/ on MacOS?
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.
Even without a grammar spec, there's lots of things common in _most_ languages: quoted strings, whitespaces, matching braces/parens, etc.
Yeah it doesn't look like this is AST-aware at all.

If you want to do queries that understand the grammar, https://github.com/getgrit/gritql is closer to what you're looking for. (Disclaimer: I'm the author.)

Ex. here's how you would search for your example of looking for a string unless it's inside a string constant. [0]

grit apply '"this_string" => `new_string` where $match <: not within string()'

[0] https://app.grit.io/studio?key=v8iA8zIbHs2uCykNpSF_G

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...

I used comby as well but it was difficult to write proper recipes.

ast-grep and gritql are both much better.

    find . [ ... find args ] | sed -e 's/nee\(dl[aeiou]\)/stack\1/g'
not to be confused with Amber, the crystal lang web framework
Or Amber, the programming language that compiles to Bash, posted here just the other day.
Most of the time if I'm doing this, it's in a git repo and I only want to affect the checked-in files so that I can easily diff my changes. So I use a combination of `git grep`, `xargs`, and `perl` via a script I named `git-gsr`:

https://gist.github.com/jaysoffian/0eda35a6a41f500ba5c458f02...

Put it in `PATH` and then: `git gsr <old> <new>`