Closed pmarreck closed 1 year ago
Haha, first ever issue with an ML backstory. Nice.
So the idea of category selection has crossed my mind but I never had the motivation to implement it, since then you'd need an interface for listing categories, selecting which (potentially multiple) categories to pick from, etc. It's a case of "solves a problem, but not one that I have, and would bring in too much baggage to bother with".
Also, regarding maintainability, using shell tools is more hassle than it's worth in terms of reliable cross platform use in a good percentage of cases.
So the net position is yes, this is a valid feature to implement, but no I won't be doing so.
A simpler fix may be to dump out the quotes and then delete the lines you don't like. This would work very well with the existing taoup-fortune
script.
Just a correction on the category thing- It was simply including the category with the (randomized) selection, but in a way that didn't bias it towards categories with few entries- hence the length of the one-liner, LOL.
So basically, you're right that this is basically taoup-fortune
but with category inclusion but without caching. I like the caching idea.
Also, regarding maintainability, using shell tools is more hassle than it's worth in terms of reliable cross platform use in a good percentage of cases.
You're right, because I've seen that (and it's extra hard to test for both while on 1 machine!), but mainly between macOS/Linux compatibility. But I don't think ruby (which, by the way, I was a huge fan of, before I got into Elixir, but am still somewhat of a fan) gets you much further, there. Ask the homebrew guy about why he had to pin his code to an old Ruby. ;)
The thing is, the taoup-fortune
script that does caching and random-picking could all be done inside taoup
itself quite easily, and much faster. Instead of puts
'ing every line, it could assemble them into a data structure, and if a -1
argument existed on ARGV, it could randomize within Ruby and just output that; providing no args would just do what it does now, except map every line to a puts
. I understand that your needs from this are already satisfied so you might not be personally motivated, but would you accept a clean implementation of something like this? Since the default behavior would be preserved, I mean.
actually, the cross platform issues are especially true of awk
which seems to require gawk
via homebrew on macOS in order to maintain GNU Awk compatibility (which is basically the default assumption in most awk scripts, as well as being POSIX I believe)... adding further complication
Sure, clean implementation welcome! However, I feel given the syntax of the ANSI library we have sort of reached a local maxima for readability already. It's difficult to see how a data structure would be any more legible. Recalling, of course, legibility is more important than other factors ...
FWIW this is not supposed to be beautiful or efficient code, just a fun tool that's easy to maintain. Since the taoup-fortune
cache implementation fixed the speed issue #11 , and we've got white terminal support through the neat hack at the top, IMHO anything else is basically tangential icing.
So I wrote a
bash
function (or is itawk
, really?) to do so:(my
needs
dependency-check function, for anyone curious:)It would be nice if this was built-in, though. Instead of outputting immediately with
puts
, you could assemble all the quote data into an array (including headers), count the number of quotes (excluding headers), pick a random number between 0 and (that count - 1), find that quote through iteration (skipping headers but noting the last one seen), and then output the last header seen and the quote.