Live data from Hacker News

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

joeyh.name

81–90 of 225 posts

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

#81
post #32
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

> rg Never going to happen because it's written in rust. ag ( https://github.com/ggreer/the_silver_searcher ) on the other hand is written in C.

+1 for ag (the_silver_searcher)

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

#82
post #27
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…

On most POSIX systems you can use fc(1) to edit a command in your $EDITOR. In vi(1) and friends you can then use "%!ls" to replace the contents of the buffer with directory listing and edit the commands you want. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/f... https://pubs.opengroup.org/onlinepubs/9699919799/utilities/v...

You just improved my life. Thank you.

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

#84

What is the difference between `sponge` and redirecting with `>` (or `>>`)? Is it about better compatibility with pipes or something?

Imo sponge is the most useful of all of them. For example if you want to filter a file in place you can do ‘grep str file | sponge file’. If you do that with a redirect you’ll end up with an empty file.

Some commands (eg. sed) have an in-place option, but many don’t.

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

#85
A lot of these seem easily achieved in a POSIX shell manner, but most annoyingly to me

> sponge: soak up standard input and write to a file

I do that all the time...

cat > file.txt

Update: reading the comments on here, apparently sponge sucks up all content before opening the destination file which allows editing an input file in place. Minor advantage there.

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

#86

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.

Didn't know about "ncd", ended up re-inventing it. The following script, named 'F', takes regexp(3) pattern in $1 and works reasonably well in the 'all text is hypertex' environment of (p9p) Acme. If it finds one match, it opens it via plumb(1). Otherwise lists results; one right-click opens the clicked result again via plumb(1).

Yes, the find -type f focuses on files; nonetheless it's easy enough to right-click-select the relevant directory to open it rather than the file.

  #!/usr/bin/env rc
  
  if (~ `{find -type f | 9 grep $1 | wc -l} 1)
   plumb `{find -type f | 9 grep $1}
  if not
   find -type f | 9 grep $1

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

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

There are Vim plugins that let you rename files and directories within Vim, such as https://github.com/qpkorr/vim-renamer.

Also if you happen to use fern[0] you can mark off multiple files and directories, hit a hotkey and now you can edit their paths in a Vim buffer.

[0]: https://github.com/lambdalisue/fern.vim

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

#88
post #85

A lot of these seem easily achieved in a POSIX shell manner, but most annoyingly to me > sponge: soak up standard input and write to a file I do that all the time... cat > file.txt Update: reading the comments on here, apparently sponge sucks up all content before opening the destination file which allows editing an input file in place. Minor advantage there.

The purpose of sponge is that you can do this:

grep foo file.txt | sponge file.txt

If you do this with redirections then file.txt will be truncated before it's been processed, leaving you with an empty file instead of what you wanted. Sponge collects its input first and then writes everything out at the end, so you can output to a file that was used as an input.

(Parent updated while I was writing. Oh well)

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

#89
post #85

A lot of these seem easily achieved in a POSIX shell manner, but most annoyingly to me > sponge: soak up standard input and write to a file I do that all the time... cat > file.txt Update: reading the comments on here, apparently sponge sucks up all content before opening the destination file which allows editing an input file in place. Minor advantage there.

[deleted]

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

#90
post #3

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

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?
Post reply on HN