Remix.run Logo
Tell HN: Fastmod Is Nice
2 points by gchamonlive 5 hours ago

I wanted to make a blog post, but life happens and I think a quick submission also does the job.

I always get aggro trying to reuse a regex that works on `rg` in `sed`. You

  rg "something I need to (change|modify)" file.md
  
It works but then

  sed -i 's/something I need to (change|break)/$1 is inevitable/g' file.md
Nothing happens...

Ah yes! Extended regex...

  sed -e -i 's/something I need to (change|break)/$1 is inevitable/g' file.md
What? Still nothing? Let me check the docs:

  sed -h 2>&1 | grep 'regex'
  -E, -r, --regexp-extended
Ah yes... its `-E`.

But fastmod, which is mentioned in at the end of https://github.com/BurntSushi/ripgrep/blob/master/FAQ.md#search-and-replace is surprisingly good, both in terms of performance/ux and compatibility.

You just:

  fastmod -m 'something I need to (change|break)' '$1 is inevitable' file.md
It will open a confirmation window for every change so you can review and apply it, which you can bypass with --accept-all, which doesn't have a shorthand which is a correct decision IMHO.