Live data from Hacker News

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

github.com

71–80 of 81 posts

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

#72

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,…

be very careful with

    git checkout .
it will eat your changes changes if you yolo it.

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

#73

We're losing the art of bash ``` find -type f -iname '*.go' | xargs -r -n1 sed -i 's,foo,foobar,g' ```

The problem is... if you use these on rare occasions it gets frustrating, because you have to read the manual or google everything or ask the llm again and again. noone can remember these abbreviations

You can save useful snippets in a file for later use.

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

#75

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,…

Pretty neat trick, I will definitely use it in the future

But it only works in git repositories. Sometimes you need to search and replace on non-git repositories, for those cases Scooter might be the answer

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

#76

We're losing the art of bash ``` find -type f -iname '*.go' | xargs -r -n1 sed -i 's,foo,foobar,g' ```

The problem is... if you use these on rare occasions it gets frustrating, because you have to read the manual or google everything or ask the llm again and again. noone can remember these abbreviations

yes, but...

noone except your shell! Fish is perfect and very very often can guess what I want using pwd, file existence, current prompt, etc...

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

#77

A useful feature of bash and zsh is the "edit command". The standard shortcut is "ctrl-x ctrl-e". It opens the current command line in $EDITOR, which often defaults to vim.

I tried this out, and nothing happened. Then I discovered that it has to be enabled first, for example by: https://unix.stackexchange.com/a/34251/152147 Thanks for sharing, learnt something new :)

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

#78

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,…

The `git gui` command is a nice-ish graphical alternative to `git add -p` and `git checkout` btw. You can even stage and discard individual lines. There are of course lots of other ones, but the TCL/Tk one is quite featureful.

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

#79
post #74

Am I the only one who thought this could alsop work lik "just" a find tool, only to discover it silently erased that word from all files in the directory without asking for confirmation? This felt riskier than rm -rf.

This should only happen if you hit enter on the confirmation screen - was it not clear that this would happen? I'd rather not slow users down by making them confirm that they definitely want to perform the replacement, but I'm happy to hear about other ways to make it clear that a replacement is going to be performed

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

#80
Love this but also could never really stick to similar tools (codemod, fastmod..)

Main change I would need I think: to assume that if no replacement if provided, the user wants to edit each instance individually "inline" (or dropping into vim, not sure what works best - this model breaks once you want to swap lines, replace 1 word with multiple lines etc).

And ofc accept command line args for the initial search string (and optionally replacement) from command line so the first screen is skipped! (I think folder could be optional)

(I also tried to undo my changes after deleting words by accident but thats a hard ask! :D)

Post reply on HN