Live data from Hacker News

Show HN: Scooter – Interactive find and replace in the terminal

github.com

51–60 of 81 posts

Re: Show HN: Scooter – Interactive find and replace in the terminal

#51
There was another comment about the difficulty in installing scooter and in the issues section, there are some requests to add more installation options.

https://github.com/thomasschafer/scooter/issues/6

Not everyone has the Rust toolchain installed on their machine. The `cargo install` installation directive needs to be discouraged.

Re: Show HN: Scooter – Interactive find and replace in the terminal

#54
post #48

Feels like we just keep making tools that already exist in Emacs.

I dunno, seems reasonable to me that we might have nice things without requiring everyone to use emacs. (And for those who do use emacs, I guess you're ahead of the curve?)

On the other hand, it seems reasonable that we should be able to have nice things without giving up our editors. I know I’ve been spoiled by Kakoune’s cursors, but this feels like a tool that should work by spawning $EDITOR in the middle of its execution (or perhaps just having two phases and a control file). I don’t know if that’s actually possible with the current capabilities of $EDITORs (which are not Emacs). I just feel, in the darkest hour of the night which I spend reflecting on UIs, like it should be.

Re: Show HN: Scooter – Interactive find and replace in the terminal

#58
You get all this and more with a direct perl one liner. Without the interactivity. I'd argue that if it is a lot of files, interactivity would be a pain. Also, since the original is preserved as a .bak file, one can be fearless about trying

   #change xxx to yyy in all html
   bash> perl -pi.bak -e 's/xxx/yyy/g' *.html

   #change xxx10 (say) to yyy10 in all html
   bash> perl -pi.bak -e 's/xxx(\d+)/yyy$1/g' *.html

   # Change x4 to yyyy, where the number of y's equals to the number after x.
   bash> perl -pi.bak -e 's/x(\d+)/"y" x $1/ge' *.
The last example shows the /e operator, which evaluates an expression and uses the result as substitute, instead of a simple string.

And finally, to exclude files, one can use a subshell. For example, suppose you want to change all html, but exclude undesirable.html..

   perl -pi.bak -e 's/x/y/g'  $(ls *.html | egrep -v undesirable)

Re: Show HN: Scooter – Interactive find and replace in the terminal

#59
Since we're all giving replacements to this, nobody's mentioned my preferred one, so: use git add's patch mode. On a clean worktree, do the search/replace in bulk. Then use `git add --patch` to selectively add the good replacements and skip the bad ones. Finally, `git checkout -- .` to throw away all the bad ones. The nice part about this is that it's not much to remember. If you can make a global search and replace, and you can use `git add --patch` (which is useful loads of times), you can do a selective search and replace by combining them.

As far as this actual tool: the demo GIF is way too fast-paced to show what's going on. A better demo would maybe search "ring", have 10 or so results instead of pages and pages, and show how you can unselect "spring" matches which were unintentionally caught.

Post reply on HN