Live data from Hacker News

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

joeyh.name

101–110 of 225 posts

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

#101
post #75

Earlier quoted context omitted.

I use Emacs shell-mode for most of my terminals, which allows navigating and editing the buffer just like any other file. I'll often make several copies of a command, then use a macro to alter each one; after checking that they look right, pressing Enter will send them all to the shell.

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?

Check out emacs-libvterm. I’ve replaced all terminal emulators with it. All the benefits of an Emacs buffer and no issues with curses or lag.

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

#102

Earlier quoted context omitted.

Linux on ARM is a very mainstream platform from the perspective I’m looking at this from, I’m afraid. I’m talking about strange Unices running on architectures that GCC may or may not maintain a backend for, or maybe a BusyBox available on some debug interface, maybe a school project to build a simple POSIX-compatible OS or a bootstrap for a platform that had been recently jailbroken. In these cases C is almost alway…

Could you give some actual examples? This sounds interesting but I'm not sure I've ever seen something like that in the wild.

This is clearly not one of the examples saagarjha was thinking of, but an actual example where Rust is not an option is the x32 ABI for x86_64 platforms. This ABI works well with GCC, but LLVM suffers from multiple code generation bugs. As Rust is based on LLVM, Rust for the x32 ABI does not work well either. While it's possible to use a mixture of ABIs, so that you have a mostly-x32 system but with some x64 binaries, this requires a multilib setup with multiple copies of system libraries. A pure x32 system cannot currently have Rust utilities.

(I have some patches to improve things but I have not been able to submit them to LLVM yet, and with those patches I did manage to get a working x32 build of rg on my system. I hope to be able to do so in the future.)

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

#103
post #95
post #88

Earlier quoted context omitted.

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)

That doesn't seem like an efficient way to do it. Commands that process file in place (sed -i) write to a temporary file in the same filesystem and then rename to the target file, which works if you want to process files that don't fit into memory.

Without inspecting the implementation of `sponge` that's how I assumed it already internally worked.

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

#104
So this where errno comes from. I discovered it by accident on my system a few years ago and have been using it ever since. Really handy when working in C. Still no idea why I have that package installed though.

On another note

> pee: tee standard input to pipes

Goddammit guys!

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

#105
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.

Not minor; it's literally the point of this tool

It lets you edit in place, which is very handy. It also keeps the original file permissions, which "blah bar > foo ; mv foo bar" does not do. Convenient. Frankly, I think that should be in the posix standard.

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

#106
post #55

Earlier quoted context omitted.

I think that's the default behaviour in Zsh or Fish if you press tab.

Probably immediate subdir. What I am talking about is universal jump-to-anywhere. Like I have subdir "/media/tnoko/sdc1/capture/Roinaa/". "ncd Roi" should be totally sufficient and unique command to go there.

For this I use autojump[0], what I really like is the integration with ranger FM[1]. I don't know exactly how ncd works, but with autojump you need to visit the directory at least one time to be able to fuzzy-jump.

0: https://github.com/wting/autojump

1: https://github.com/fdw/ranger-autojump

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

#107

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.

Ach. It was "Norton Change Directory" http://www.softpanorama.org/OFM/norton_change_directory_clon...

But I already made my own. It is quite perfect:

    #! /bin/bash
     d=$(find /  -name "$1" 2>/dev/null | head -1)
     echo Jumping to $d, Control-D to return 
     sleep 1
     cd $d
     bash

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

#108
post #95
post #88

Earlier quoted context omitted.

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)

That doesn't seem like an efficient way to do it. Commands that process file in place (sed -i) write to a temporary file in the same filesystem and then rename to the target file, which works if you want to process files that don't fit into memory.

I apologise, I was speaking loosely. I don't know if sponge collects input in memory or in a file. (Frankly I've never needed to care since the files I've ever needed this tool for have all been small)

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

#109

Earlier quoted context omitted.

But the top answer has it: > find . -maxdepth 1 -type f A little clunky, but there's certainly no need to mess about in JavaScript land. If you use it often, create a shell macro.

find doesn't return the same output as ls when run on another directory. Maybe there is a switch to do this? I'm not sure. $ mkdir -p tmp && touch tmp/a tmp/b tmp/c $ find ./tmp -maxdepth 1 -type f ./tmp/a ./tmp/c ./tmp/b $ ls -1 ./tmp a b c

    +   $ find /tmp/x ! -path /tmp/x -prune -type f -exec sh -c 'for p; do printf '\''%s\n'\'' "${p##*/}"; done' - {} +
    c
    b
    a
Seems to do the trick and is POSIX only (so works on busybox and mac). You can probably just tack `| sort` at the end if you want it sorted.
Post reply on HN