9 ms·
Amber: A code search and replace tool
- laerus 2y agoAt this rate of naming projects after the same valuable stones, we are going to need namespacing for the CLI tools.
- ape4 2y agoUse amber to search through your amber code
- tazjin 2y agoThis project has been around for a while.
- ecshafer 2y agoOff 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 2y agoDang 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 2y agorelated, 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.
- laerus 2y agobut mine can be read backwards
- pizzafeelsright 2y agoAmber is the ex who keeps digging up the past.
- wormius 2y agoThere'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.
- danilonc 2y agoReminded me of https://github.com/ast-grep/ast-grep https://github.com/ast-grep/ast-grep and I wonder how it compares in performance and functionality.
- danilonc 2y agoast-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 2y agoThis used the more sound approach of treating code as code
- herrington_d 2y agoast-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/9f8ed5fb2abf35d9280a05b17ed49c888f5a9aad/crates/cli/src/utils.rs#L216-L233 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 2y agohttps://github.com/BurntSushi/ripgrep https://github.com/BurntSushi/ripgrep ???
- zsyllepsis 2y agoThe author specifically mentions, and benchmarks against, ripgrep in the linked content.
- kstrauser 2y agoRipgrep lacks the “& replace” bit.
- cess11 2y agoNah. $ rg 'sear' -r 'repl' file.txt
- burntsushi 2y agoThat only replaces in the output. ambr seems to actually modify the file contents, like `sed -i`. ripgrep never modifies the contents of files.
- cess11 2y agoRight, 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.
- pdimitar 2y agoripgrep 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.
- VagabundoP 2y agohttps://news.ycombinator.com/item?id=40431835 https://news.ycombinator.com/item?id=40431835 EDIT: Opps same name different project.
- forgotpwd16 2y agoSeems 'amber' a popular name. A dynamics package, an hypothetical operating system, a framework, a Java enhancing project, a VM, a language, now a tool.
- jes5199 2y agoI'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 2y agoIs it possible to store my config files under ~.config/amber/ on MacOS?
- saurik 2y agoI 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 2y agoEven without a grammar spec, there's lots of things common in _most_ languages: quoted strings, whitespaces, matching braces/parens, etc.
- alexpovel 2y agoThe tool you are describing is what I am trying to build at https://github.com/alexpovel/srgn https://github.com/alexpovel/srgn . The idea is a compromise between regex (think ripgrep) and grammar awareness (through tree-sitter).
- herrington_d 2y agoHey! ast-grep author here. I believe what you want is probably what https://github.com/ast-grep/ast-grep 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#eyJtb2RlIjoiUGF0Y2giLCJsYW5nIjoidHlwZXNjcmlwdCIsInF1ZXJ5IjoidmFyaWFibGUiLCJyZXdyaXRlIjoiIiwiY29uZmlnIjoiaWQ6IGludGVybmFsLW1ldGhvZC1ub3QtYW5ub3RhdGVkIFxucnVsZTpcbiAga2luZDogbWV0aG9kX2RlZmluaXRpb25cbiAgaGFzOlxuICAgIGZpZWxkOiBuYW1lIFxuICAgIHJlZ2V4OiBeLipJbnRlcm5hbCRcbiAgbm90OlxuICAgIGZvbGxvd3M6XG4gICAgICBwYXR0ZXJuOiAvKiogQGludGVybmFsICovIFxuIiwic291cmNlIjoiY29uc29sZS5sb2codmFyaWFibGUpXG5jb25zb2xlLmxvZygndmFyaWFibGUgaW4gc3RyaW5nJykifQ== https://ast-grep.github.io/playground.html#eyJtb2RlIjoiUGF0Y...
- morgante 2y agoYeah 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 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 https://app.grit.io/studio?key=v8iA8zIbHs2uCykNpSF_G
- dmix 2y agoI used to use https://comby.dev/ 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 https://github.com/piranha/goreplace as backup which is much simpler but reliable. I'll check this one out...
- pdimitar 2y agoI used comby as well but it was difficult to write proper recipes. ast-grep and gritql are both much better.
- PaulDavisThe1st 2y agofind . [ ... find args ] | sed -e 's/nee\(dl[aeiou]\)/stack\1/g'
- Singletoned 2y agoCan it do multiline search and replace?
- pdimitar 2y agoast-grep and gritql can.
- malthejorgensen 2y agoFeels similar to `sd` (https://github.com/chmln/sd https://github.com/chmln/sd) which in my mind was the first “replace” version of ripgrep grep -> ripgrep sed -> sd
- sam0x17 2y agonot to be confused with Amber, the crystal lang web framework
- replwoacause 2y agoOr Amber, the programming language that compiles to Bash, posted here just the other day.
- js2 2y agoMost 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/0eda35a6a41f500ba5c458f02a29865d https://gist.github.com/jaysoffian/0eda35a6a41f500ba5c458f02... Put it in `PATH` and then: `git gsr <old> <new>`
- nathants 2y agothis is cool! i do the same thing[1], wanted ag/rg to be able to search and replace. 1. https://github.com/nathants/agr https://github.com/nathants/agr
- harryquach 2y agoNot to be confused with this Amber https://amber-lang.com/ https://amber-lang.com/