Live data from Hacker News

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

joeyh.name

221–225 of 225 posts

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

#221
post #211

Earlier quoted context omitted.

I've got a hand rolled direnv that's quite simple: function lenv { path=$PWD while [[ ! -f "$path/.env" && "$path" != '/' ]]; do path=$(dirname "$path") done if [ -f "$path/.env" ]; then source "$path/.env" fi } function cd { builtin cd "${@}"; lenv; } It lacks the security but it works recursively and allows more than just environment variables. A common script I have is to automatically build for instance: here=$(d…

direnv does allow more than just environment variables, you can run arbitrary commands. Personally I wouldn't run potentially expensive commands like building the project, but if that's really what's best for your workflow, it can be done. If there is no .envrc in the directory it will look for one in the parent directory, but it won't activate more than one. Also one thing it does that your hand-rolled version does…

> Personally I wouldn't run potentially expensive commands like building the project

My above example wasn't running the command, just defining it to be run manually. The .env becomes a dumping ground for all sorts of project specific stuff. The docs say direnv doesn't support this.

> Also one thing it does that your hand-rolled version does not is that it remembers what the environment variables were before and restores them to that state when you exit the directory.

I've thought of adding this, but apart from a couple of things I reset manually I haven't really found the need.

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

#222
post #11

It's funny that `vidir` spawns `nano` by default on my system.

That'd be the Debian alternatives system in action. $ update-alternatives --list editor

Or sensible-editor.

* http://jdebp.uk./FGA/unix-editors-and-pagers.html

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

#223
Yes, they weren't written "when Unix was young", but people had thought to write some of them over a decade before this toolset. lckdo and ts came long after setlock and cyclog (also the precursor to multilog) from the 1990s.

* https://cr.yp.to/daemontools/setlock.html

* http://cr.yp.to/daemontools/multilog.html

* http://cr.yp.to/daemontools/upgrade.html

* http://jdebp.uk./Softwares/nosh/guide/commands/cyclog.xml#CO...

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

#224
post #221

Earlier quoted context omitted.

direnv does allow more than just environment variables, you can run arbitrary commands. Personally I wouldn't run potentially expensive commands like building the project, but if that's really what's best for your workflow, it can be done. If there is no .envrc in the directory it will look for one in the parent directory, but it won't activate more than one. Also one thing it does that your hand-rolled version does…

> Personally I wouldn't run potentially expensive commands like building the project My above example wasn't running the command, just defining it to be run manually. The .env becomes a dumping ground for all sorts of project specific stuff. The docs say direnv doesn't support this. > Also one thing it does that your hand-rolled version does not is that it remembers what the environment variables were before and rest…

Ohh, okay, I see.

You're right, you can't define aliases/functions using direnv. That's a shame, that does seem useful.

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

#225
post #201
post #198

Earlier quoted context omitted.

Some of the above can easily be written in C or Python or Ruby (and some of the simpler ones even in shell), at least for simple versions, maybe without all the frills of the originals. And seq in Linux is like jot for sequential data, at least. And from my blog: An Unix seq-like utility in Python: https://jugad2.blogspot.com/2017/01/an-unix-seq-like-utility...

Yes, they're generally available in some form (now generally including the ‘originals’ now that V8–V10 have been published). And they're all very simple, which is the whole point of Unix tools. I've found I'm using the `put`/`take` pair, for splitting a pipeline across shells, more again in the WFH era where I often have multiple ssh sessions into a machine, when I would probably have used the clipboard in a GUI sess…

>And they're all very simple, which is the whole point of Unix tools.

Not all Unix tools are simple. E.g. make. But I know what you mean - the Unix philosophy.

https://en.m.wikipedia.org/wiki/Unix_philosophy

The TAOUP book by Eric Raymond (The Art Of Unix Programming) has a lot about that.

https://en.m.wikipedia.org/wiki/The_Art_of_Unix_Programming

And my IBM developerWorks tutorial / case study on Developing a Linux command-line utility (in C) may be of interest to people who want to write their own Unix tools that play well with others.

https://jugad2.blogspot.com/2014/09/my-ibm-developerworks-ar...

Post reply on HN