>What's pty good for? I wrote the first versions of pty so that I could run pty nethack inside a script which would keep rerolling characters until I had both a ring of polymorph and a ring of polymorph control
Funny I wrote the same kind of start-scumming script against nethack.org using Python and pexpect.
I am curious with the use cases for something like this might be. I feel like it's very rare nowadays to encounter a CLI/TUI program that doesn't have a "non-interactive" alternative, either in a different tool or built into the application itself.
I know that pexpect can be used for testing such applications though. Is this meant to be for a similar use case? Or were "interactive-only" tools more common at one time in the past?
I sometimes want "nobuf" or something like it. I run some command that produces output promptly. Then I pipe it through grep or tee and the output doesn't show up as promptly, because it's switched from line buffering to block buffering. "nobuf" fixes this.
There's a command called "stdbuf" on Linux systems that accomplishes the same thing in a different way. It sets some magic environment variables [1], and that tells the subprocess to use line buffering, assuming it's using glibc [edit: or any dynamically-linked libc] and stdio. No pty actually required then.
stdbuf's manpage has an example:
tail -f access.log | stdbuf -oL cut -d ' ' -f1 | uniq
This will immediately display unique entries from access.log
[1] edit: just checked. It injects its own code via the LD_PRELOAD environment variable, and then controls that with other environment variables. LD_PRELOAD is gross but it works, I guess.
I typically play on public servers to avoid any save game temptations, or the reverse, removing terrifying bones infested with rogue pet vampires and cursed artifacts...
I'm disappointed that DJB didn't automate polypiling until he got what he wanted, rather than just rolling new characters until getting the desired combination of resources. At that point, I'd just say that save game editing and RNG grinding are comparable...
If you're reading this, DJB, thanks for all the awesome and weird tools! Perhaps you're not as widely attributed as you should be but I see your influences everywhere in modern unix.
(edited to change "fingerprints" to "influences" -- things like systemd or the later solaris init replacement are clearly a funhouse mirror re-imagning of daemontools and family -- but fingerprints implies that DJB touched these things which I'm pretty confident he didn't)
There are a bunch of aspects to optimal play in NetHack that are pretty unfun for humans to perform (but dramatically increase win rate). These things can all be programmed into an AI without too much trouble, some more fiddly than others:
* Always retrace your own steps when backtracking. Only walk on new tiles when it’s absolutely necessary for exploration. This greatly reduces your chances of stepping on unseen traps.
* Abuse shops to the max. Price ID everything you find. Sell every last bit of junk. Engage in credit cloning. Steal everything from shops.
* Abuse the protection racket. Max out on divine protection by spending all of the money from every shopkeeper’s pocket at the temple in minetown.
* Abuse alchemy to make large stacks of holy water and blessed potions of full healing. Increase your max HP to several hundred.
* Pudding farming. This one has thankfully been patched out.
* Polypiling. Polymorph lines of items on the floor. Try to get magic markers to write more scrolls of enchant armour.
Bit of an edge use case but I had a backup server that the ssh would only take a password from interactive keyboard wouldn't accept the password argument for scp. Something like this could have fixed the issue, I ended up just going for a different provider that allowed ssh keys.
OpenSSH also supports using a script to get the password if using the `SSH_ASKPASS` environment variable, and being invoked under a non-tty input e.g.
{ echo '#!/bin/sh' ; echo 'echo my_password' ; } > password.sh # don't do it like this :-p
chmod +x password.sh
SSH_ASKPASS=./password.sh DISPLAY= setsid ssh user@host /bin/id
In newer SSH versions `DISPLAY` is not required (but there is a new `SSH_ASKPASS_REQUIRE` environment variable), but in older (e.g. 8.x) versions, then it needs to be set as the default ssh-ask-password was an X11 command, and I believe the logic assumed that scenario.
The most common use-case I can think of (and one I've often wanted myself) is programs that only colorize when writing to a terminal, and you want to save the output but still keep the colors.
It's pretty easy to inspect the nethack state since it's all text. When I wrote a script to reroll nethack characters in the past, I just opened the inventory and used "grep" to search for desired items.
Funny I wrote the same kind of start-scumming script against nethack.org using Python and pexpect.