Live data from Hacker News

Bash patterns I use weekly

will-keleher.com

51–60 of 115 posts

Re: Bash patterns I use weekly

#52
post #3
post #2

> git bisect is the "real" way to do this, but it's not something I've ever needed git bisect is great and worth trying; it does what you're doing in your bash loop, plus faster and with more capabilities such as logging, visualizing, skipping, etc. The syntax is: $ git bisect run [arguments] https://git-scm.com/docs/git-bisect

Yes, git bisect is the way to go: in addition to the stuff you mentioned, his method only dives into one parent branch of merge commits. git bisect handles that correctly. A gem of a tool, git bisect.

Bisect also does a binary search so if you're looking for one bad commit amongst many others, you'll find it much more quickly than linearly testing commits, one at a time, until you find a working one.

Re: Bash patterns I use weekly

#53

Earlier quoted context omitted.

Using an IDE kind of handicaps you to only working with your IDE though. The shell works everywhere for every use case.

That particular IDE works on Windows though… no idea how to use Powershell…

WSL2?

Re: Bash patterns I use weekly

#54
post #31

> 1. Find and replace a pattern in a codebase with capture groups > git grep -l pattern | xargs gsed -ri 's|pat(tern)|\1s are birds|g' Or, in IDEA, Ctrl-Shift-r, put "pat(tern)" in the first box and "$1s are birds" in the second box, Alt-a, boom. Infinitely easier to remember, and no chance of having to deal with any double escaping.

Yea, I've yet to come across a regex replacement tool as easy to use as jetbrains find & replace. Invaluable for certain tasks.

Re: Bash patterns I use weekly

#58
post #7

I want to like this, but the for loop is unnecessarily messy, and not correct. for route in foo bar baz do curl localhost:8080/$route done That's just begging go wonky. Should be stuff="foo bar baz" for route in $stuff; do echo curl localhost:8080/$route done Some might say that it's not absolutely necessary to abstract the array into a variable and that's true, but it sure does make edits a lot easier. And, the orig…

Even more correct would be to use an array: stuff=("foo foo" "bar" "baz") for route in "${stuff[@]}"; do curl localhost:8080/"$route" done

Yes that is more correct, I describe that here:

Thirteen Incorrect Ways and Two Awkward Ways to Use Arrays http://www.oilshell.org/blog/2016/11/06.html

In Oil the syntax is simplified to

    const stuff = %("foo foo" bar baz)
    for route in @stuff {
      curl localhost:8080/$route  # no quotes needed
    }
Post reply on HN