Live data from Hacker News

Moreutils – Unix tools that nobody thought to write (2012)

joeyh.name

121–130 of 225 posts

Re: Moreutils – Unix tools that nobody thought to write (2012)

#121
post #97
post #3

> sponge Why not use > file? > mispipe In bash there's PIPESTATUS for that.

> Why not use > file? This, I learned the hard way, and I am not the only one. So in order for you not to make that mistake: the first thing that happens is that "file" is truncated, that happens before any command is run, so sed s/foo/bar/ file > file will always result in an empty "file", because it will be truncated before "sed" is run. I lost a couple of hours of work like that, once, and then I learned. From the…

Try

    sed s/foo/bar/ -i file 
to edit file.

Re: Moreutils – Unix tools that nobody thought to write (2012)

#122
post #75

Earlier quoted context omitted.

I always tried to use the shell with emacs (eshell, multi-term) but it didn't render correctly curses and all the fancy stuffs like emojis. Out of curiosity, how do you manage that?

Usually with ansi-term instead, if I'm honest. Also look into emojify-mode if your system doesn't handle emoji fonts well or at all.

Belatedly to add - look into the eshell-visual-* lists, to configure commands, subcommands (like "git log"), and I think some other traits, such that matching commands get their own ansi-term buffer.

Re: Moreutils – Unix tools that nobody thought to write (2012)

#123

ts looks like it's a subset of https://github.com/ThomasHabets/ind sponge can be replaced with dd Other than that, yeah nice ideas. And very much in the unix spirit of one tool to do one thing.

sponge buffers the whole input before writing the output. Its utility would be in reading from a file, working on it with other tools, and writing the result back to the original file, all in one line.

Re: Moreutils – Unix tools that nobody thought to write (2012)

#124
I seriously hate this package and the manner of combining different utils with different names in a same package in general. The reason being, "sponge" is an actually useful tool and for me it's pretty much the only useful tool in the package. So I need to install whole moreutils package on ubuntu to have "sponge" and I have to clog my bin namespace with all this trash. It would be mildly annoying from the perfectionist point of view, but ok. But there is also "parallel" command in this package, which is trash as well. Meanwhile GNU "parallel" is not trash, but an actually useful program, maybe more useful than "sponge", and it comes in a separate package. So I either have to do some tinkering, or I have to choose which one I need more: "sponge" or "parallel" and install only one package. It's year 2020. This is stupid.

This is by the way the reason why GraphicsMagick is better than ImageMagick (I still use the latter, though, because it doesn't cause the same problems for me as moreutils does, and it's just more popular than GM).

Re: Moreutils – Unix tools that nobody thought to write (2012)

#125
post #31

There's a few programs I wish were standard on all Unix systems by now: * tree - print directory structure * bat - cat, but actually designed for reading files. Syntax highlighting, line numbers, automatic paging. * rg - better grep * direnv - local environment variables

I don't think they should be standard at all. I am familiar with all of them pretty much since the moment they are born (which is not that long, TBH) and the only one I actually use is tree. Which is also quite a judgement call, since it can be replaced by exa, which is more powerful (I'm considering it; I'm pretty sure that you will like it, BTW, so take a look). bat is useless, since there is vim/view. rg is actually good, but cannot be used as a drop-in replacement for ag (I don't remember what the problem is exactly, but I tried several times and burntsushi even gave me some advice on that, and I still use ag, which is slower, so I assume there actually was some serious reason). And, by the way, no, neither of them is actually a replacement of grep.

(Also, yeah, let's ignore that Rust in the standard libraries is still a problem.)

Re: Moreutils – Unix tools that nobody thought to write (2012)

#126
post #123

ts looks like it's a subset of https://github.com/ThomasHabets/ind sponge can be replaced with dd Other than that, yeah nice ideas. And very much in the unix spirit of one tool to do one thing.

sponge buffers the whole input before writing the output. Its utility would be in reading from a file, working on it with other tools, and writing the result back to the original file, all in one line.

I know I wanted to do this, but I am very happy such a utility doesn't exist. Unix utilities, usually work in a pipeline fashion, read line -> process -> write to output. This allows them to allocate a limited amount of memory. If you read all input in memory, you are asking for trouble: 'cat /dev/zero | sponge a'.

Re: Moreutils – Unix tools that nobody thought to write (2012)

#127

The sponge example: sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd I think it can be rewritten as: sed -n '/joey/! s/root/toor/p' -i /etc/passwd

Yes, but -i on sed is specific to GNU, I don't think it exists on BSD/OSX/busybox

-i is definitely not specificed by POSIX, but it supported on all those platforms with some small differences, for instance on OSX the backup extension (-i.bak) is not optional.

Re: Moreutils – Unix tools that nobody thought to write (2012)

#128

Where is Msdos utility "ncd"? It was like "cd" but guessed from few character hint where you wanted to go. If the choice was not immediately obvious if offered a menu or a tree. I shortened it to "n". -- There was some linux utility but setting it up was annoyingly tedious, with lots of useless and cryptic options.

Use z[1]. Also use fzf.

[1] - https://github.com/skywind3000/z.lua

Re: Moreutils – Unix tools that nobody thought to write (2012)

#129
post #124

I seriously hate this package and the manner of combining different utils with different names in a same package in general. The reason being, "sponge" is an actually useful tool and for me it's pretty much the only useful tool in the package. So I need to install whole moreutils package on ubuntu to have "sponge" and I have to clog my bin namespace with all this trash. It would be mildly annoying from the perfection…

Is there a way to namespace on install? Or does that have to be configured in the package?

Re: Moreutils – Unix tools that nobody thought to write (2012)

#130
post #15

Nice collection of quite useful tools. Some of these can be easily replicated by using a more modern shell (bash, zsh) like mispipe, others are just shortcuts (e.g. ifne, chronic). But what immediately stood out to me is `vidir`. I really like the idea of editing file names with an editor. Using loops and regex in a shell for mass renaming can be a mess. It should be way easier with `vim`. This tool made me install m…

> vidir

I just use ranger for that.

Post reply on HN