Live data from Hacker News

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

github.com

61–70 of 81 posts

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

#61
post #7

I'm using this quickly put-together shell script called replace #!/usr/bin/env bash # Function to escape special characters for sed escape_sed_string() { printf '%s\n' "$1" | gsed -e 's/[]\/$*.^[]/\\&/g' } help() { gum style --foreground cyan --italic "\ Usage (everything optional, you will be prompted):\n\ $0\n\ --ext .js --ext .ts\n\ --from \"source string\"\n\ --to \"replacement string\"\n\ --dir somePath" } # Par…

What is gum?

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

#63

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

Something that frequently trips me up, mostly when helping colleagues, is the arguments to both find and xargs differ substantially between GNU and the FreeBSD-derived ones that ship on macOS.

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

#64

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

Why use `xargs` instead of `-exec`? And if you do need `xargs` (for example, for parallel processing with `-P`), it is recommended to use `-print0` with `find` and `-0` with `xargs` to avoid issues due to filenames.

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

#65
post #64

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

Why use `xargs` instead of `-exec`? And if you do need `xargs` (for example, for parallel processing with `-P`), it is recommended to use `-print0` with `find` and `-0` with `xargs` to avoid issues due to filenames.

xargs passes many inputs to one script invocation, so even with a single thread there is often a dramatic speedup.

(and agree re -print0/-0, it's absolutely essential)

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

#66

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

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

#67

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

https://atuin.sh/ is such a huge productivity booster in these scenarios. I remember that I used find + xargs command sometime in the last 6 months on of my computers and with Atuin I can quickly find it and then slightly modify it to fit my current need.

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

#68
post #61
post #7

I'm using this quickly put-together shell script called replace #!/usr/bin/env bash # Function to escape special characters for sed escape_sed_string() { printf '%s\n' "$1" | gsed -e 's/[]\/$*.^[]/\\&/g' } help() { gum style --foreground cyan --italic "\ Usage (everything optional, you will be prompted):\n\ $0\n\ --ext .js --ext .ts\n\ --from \"source string\"\n\ --to \"replacement string\"\n\ --dir somePath" } # Par…

What is gum?

it's a cool helper for shell scripts, do have beautiful interfaces, check it here https://github.com/charmbracelet/gum

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

#70
post #65
post #64

Earlier quoted context omitted.

Why use `xargs` instead of `-exec`? And if you do need `xargs` (for example, for parallel processing with `-P`), it is recommended to use `-print0` with `find` and `-0` with `xargs` to avoid issues due to filenames.

xargs passes many inputs to one script invocation, so even with a single thread there is often a dramatic speedup. (and agree re -print0/-0, it's absolutely essential)

`find` can do that as well with `{} +` (at least, the `GNU` implementation and it'll automatically add more invocations if there are just way too many files).

In any case, OP was using `-n1` which means one file per invocation.

Post reply on HN