Live data from Hacker News

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

joeyh.name

151–160 of 225 posts

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

#151
post #79

Earlier quoted context omitted.

I'm on MacOS... :-/ $ find ./tmp -maxdepth 1 -type f -printf '%f\n' find: -printf: unknown primary or operator

If you use brew or macports you can install the coreutils package and then you're good to go with gnu find. I also use MacOS and I have setup the gnu userland on my local so it matches the linux environment on our servers and containers.

You’re right that defaulting to the GNU coreutils is probably more convenient. However, NOT doing this is a good way to ensure that any scripts you write remain portable and don’t use GNU extensions. That’s the reason I stick with the default BSD coreutils on macOS.

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

#152
post #123

Earlier quoted context omitted.

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'.

That is the point.

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

#153

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.

Consider fzf: https://github.com/junegunn/fzf

I have it bound to ctrl-e for edit: https://gist.github.com/FeepingCreature/5f575b6fcda041a48f58...

It's like adding the vscode file finder to bash :)

The additional code is to make bash "act as if you typed in the command manually". So you can arrow-up to find it in the history buffer with the filename expanded.

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

#154

Earlier quoted context omitted.

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.

Amazingly, there is no portable way to use -i that works on both GNU and BSD sed implementations. Which means if you’re writing a portable script, you can’t use -i at all.

(Would love to be proved wrong on this)

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

#155

Earlier quoted context omitted.

Re sponge: the shell will open the output file for writing before invoking the command so in the example joey provides, /etc/passwd will be an empty file by the time sed opens it.

That makes sense but in the example provided, why can't we use sed with the in-line flag?

Because the -i flag works differently on GNU sed vs non-GNU sed and there is no way to use it portably.

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

#156
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…

How is sponge different from just normal file redirection?

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

#157
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

> tree I agree, tree is great. It can be somehow replicated by using "find .", if you are in a hurry. > bat If you need that functionality, why don't you open the file with vim, for example? > rg - better grep Grep is pretty nifty, I don't see how could it be improved. What is the main advantage of of rg over grep? > direnv - local environment variables I read the manpage for direnv and I was really scared. What is i…

direnv is super useful if you're working in Python and have multiple projects: you can add an .envrc file that activates the right virtualenv whenever you enter a directory. It's one less thing to worry about.

I figure you can also use it in conjunction with `module load` to automatically load the right module when you enter a project's directory. Modules are used in many computing clusters to manage environments.

Also direnv will never execute an .envrc without permission, you need to run `direnv allow` whenever there is a new or newly modified .envrc.

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

#158
post #135

Earlier quoted context omitted.

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

I am not aware of such a way with apt on ubuntu. It can be different with some other package managers, obviously.

dpkg-divert

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

#159

Earlier quoted context omitted.

I’ve never seen syntax highlighting in “less”.

Ha! Here’s how to have syntax highlighting while using less: https://superuser.com/questions/71588/how-to-syntax-highligh...

While I don't use syntax highlighting, I find `lesspipe` useful for files that have a reasonable ‘presentation form’ as well as a source form — html, markdown, etc.

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

#160
post #156
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…

How is sponge different from just normal file redirection?

See the first example on the web page:

  % sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd
If you tried this as:

  % sed "s/root/toor/" /etc/passwd | grep -v joey > /etc/passwd
The shell would overwrite /etc/passwd with an empty file before sed has a chance to read from it.
Post reply on HN