Live data from Hacker News

Go Replace - simple and fast search and replace tool for command line

solovyov.net

21–30 of 64 posts

Re: Go Replace - simple and fast search and replace tool for command line

#21
post #19

This isn't working for me. I get: C:\Users\swah\docs>gr TEST panic: Given path should be anchored at / goroutine 1 [running]: main.NewIgnorer(0xc08005bcf0, 0x29, 0x0, 0x0, 0x140110, ...) /Users/piranha/dev/go/src/goreplace/ignore.go:32 +0xa4 main.main() /Users/piranha/dev/go/src/goreplace/goreplace.go:62 +0x1b7 goroutine 2 [runnable]: [edit] New version is working!

Argh! I see, I think I can solve this. Give me a bit of time please. :)

Re: Go Replace - simple and fast search and replace tool for command line

#22
Okay, so what I learnt from this:

1. You've imported droundy/goopt, wsxiaoys/terminal really easily. The first provides option-parsing, and the second provides helpers for emitting ANSI escape codes.

2. Practically everything is overloaded. You can == to strcmp(), + to concatenate strings.

3. path/filepath gives you some nice goodies for path manipulation. But you have to deal with the fallouts of making naive assumptions like whether or not to recurse symlinks (why isn't this a flag in filepath.Walk?). This has resulted in ugliness in your walkFunc callback.

4. You have been able to abstract quite a bit without using Java-like factories, although your inconsistent error passing has me somewhat confused.

5. Since it's so strongly typed and there are no raw pointers, it's not going to be hard to debug at all.

Overall, I'd say Go is an effective language. But not beautiful, or novel in the slightest. It resembles Algol-68 (yes, a 1968 language) quite strongly, and I don't think it will drive compiler technology. Their syntax is specifically engineered to be parseable quickly (and hence super-fast AOT compilation): what the final program looks like is secondary concern. I'm not sure I see the appeal.

[edit: clarified that the note on compiler technology was an opinion]

Re: Go Replace - simple and fast search and replace tool for command line

#23
post #19

This isn't working for me. I get: C:\Users\swah\docs>gr TEST panic: Given path should be anchored at / goroutine 1 [running]: main.NewIgnorer(0xc08005bcf0, 0x29, 0x0, 0x0, 0x140110, ...) /Users/piranha/dev/go/src/goreplace/ignore.go:32 +0xa4 main.main() /Users/piranha/dev/go/src/goreplace/goreplace.go:62 +0x1b7 goroutine 2 [runnable]: [edit] New version is working!

Should be fixed, can you download new version please?

Re: Go Replace - simple and fast search and replace tool for command line

#24
post #12
post #9

I really like Facebook's codemod.py for stuff like that: https://github.com/facebook/codemod It has something like automatic and manual modes, so you can check (and fix) every diff during the replacement

Well you see... It's in Python, which breaks the deal for me (I despise slow startup). But interactive mode sounds interesting, that's something I'll consider implementing.

By slow startup do you mean 0.01s of wall time? This sounds more like a prejudice than a decision with a strong technical basis.

Re: Go Replace - simple and fast search and replace tool for command line

#25
post #23
post #19

This isn't working for me. I get: C:\Users\swah\docs>gr TEST panic: Given path should be anchored at / goroutine 1 [running]: main.NewIgnorer(0xc08005bcf0, 0x29, 0x0, 0x0, 0x140110, ...) /Users/piranha/dev/go/src/goreplace/ignore.go:32 +0xa4 main.main() /Users/piranha/dev/go/src/goreplace/goreplace.go:62 +0x1b7 goroutine 2 [runnable]: [edit] New version is working!

Should be fixed, can you download new version please?

Working! Do you use colors? They don't work the same in DOS, I believe. I'm seeing some escape sequences.

    ←[0;32;49mRS\terms.tex
    ←[0m←[1;39;49m←[0;33;49m25:←[0m   ←[0;39;43mOEM←[0m  &                                      \\ \hline

Re: Go Replace - simple and fast search and replace tool for command line

#26

Okay, so what I learnt from this: 1. You've imported droundy/goopt, wsxiaoys/terminal really easily. The first provides option-parsing, and the second provides helpers for emitting ANSI escape codes. 2. Practically everything is overloaded. You can == to strcmp(), + to concatenate strings. 3. path/filepath gives you some nice goodies for path manipulation. But you have to deal with the fallouts of making naive assump…

and proudly declares that it will not use any modern advances to compiler technology

Where do they say anything of the kind?

Re: Go Replace - simple and fast search and replace tool for command line

#27

Okay, so what I learnt from this: 1. You've imported droundy/goopt, wsxiaoys/terminal really easily. The first provides option-parsing, and the second provides helpers for emitting ANSI escape codes. 2. Practically everything is overloaded. You can == to strcmp(), + to concatenate strings. 3. path/filepath gives you some nice goodies for path manipulation. But you have to deal with the fallouts of making naive assump…

> your inconsistent error passing has me somewhat confused.

That was my first somewhat big program in Go plus coming from Python made a bit of hustle here. I still believe exceptions to be much better than this error-returning. :\ Never learned to do it nicely. :\

> Overall, I'd say Go is an effective language. But not beautiful, or novel in the slightest.

Yes, this is more or less my feelings nowadays. It's good for certain cases and if I ever need something fast, I'll use Go and not C.

> I'm not sure I see the appeal.

There is some. It's still much simpler than C (GC + stricter compiler), plus it has goroutines (not much in this app, though), plus interfaces are really wonderful (you don't need to declare that you implement interface, just implement it and you're done).

Re: Go Replace - simple and fast search and replace tool for command line

#28
post #6

Wow, it's super fast AND the output looks great. Good job, piranha! Copied to /usr/bin, I will use this a lot.

If you're the only user on your box, you can just create ~/bin and some distributions will automatically add it to your personal PATH. That way you don't lose track of what you've copied into /usr/bin, leaving it to be maintained by packages.

you can also very easily add ~/bin to PATH in e.g. your .bashrc

Re: Go Replace - simple and fast search and replace tool for command line

#29
post #25
post #23

Earlier quoted context omitted.

Should be fixed, can you download new version please?

Working! Do you use colors? They don't work the same in DOS, I believe. I'm seeing some escape sequences. ←[0;32;49mRS\terms.tex ←[0m←[1;39;49m←[0;33;49m25:←[0m ←[0;39;43mOEM←[0m & \\ \hline

Oh, it's the library I use has no idea about colors in DOS. :( I'll have to do some research on how to fix this... :\

Re: Go Replace - simple and fast search and replace tool for command line

#30

find ~/my/docs/ -type f -name '*.txt' -exec sed -i.bak 's/inheritance/composition/g' {} + This will search all files ending in `.txt` and will exec `sed 's/inheritance/composition/g'` on it. Sed modifies files in-place and saves a backup file with .bak extension (-i.bak) and is called the minimum necessary times (-exec +). My best advice to someone using the command line is to learn `find` + `xargs` or, even better,…

Compare with "gr what-is-it -r here-you-go". I do not have to remember all that argument hell.

Well, one can write an one-line shell alias (or script) instead of reinventing the wheel by rewriting the whole thing anew in Go. (Which is certainly good as learning experience for Go, but the end result is easier to achieve with the shell)
Post reply on HN