food, +
hey @certifiedperson! @Leucrotta!
We've been trying plant-based fake meat these past couple days and it's really good!!
We can actually have like fish sticks and stuff without actually having to eat other critters, which is really nice.
...This'd be better with some rice. I wonder how hard rice cookers are to use.
re: food, +
@frost @certifiedperson unix shell?
tangent, shell infodumping
@Leucrotta @certifiedperson fish is actually REALLY different from the other ones
most of them are sh derivatives, and add some of their own stuff on top. csh is a bit of its own thing. But fish is "let's throw all that out the window and do our own thing from scratch". From what we've seen it's /very/ opinionated, in the "the devs' way is The Way To Do Things" sense.
We like zsh because it has lots of cool stuff while NOT being opinionated like that; it's a normal sh-family shell, and just adds stuff like really fancy pattern-matching and /multiline input/ (!!).
tangent, shell infodumping
@Leucrotta @certifiedperson (things like "*(om[1])" to get "all files, sorted by modification date, and only one of them" = the last modified file. It's slightly obtuse but ridiculously useful.)
@Leucrotta @certifiedperson ... inb4 I wind up infodumping you into knowing how to shell script
@Leucrotta @certifiedperson (not that it's all that useful for you probably... Windows has its /own/ shell called Powershell and it's completely different.)
yet more infodumping
@Leucrotta @certifiedperson oh yeah that's ANOTHER thing
so Unix utilities tend to work like "take in text, do something, spit out text"
things like grep, which takes input and filters it by a pattern you give it. You can run it on files, or pipe some other command into it. There's sed, which lets you do search-and-replace (and some other line-processing things, but 99% of the time it's search and replace), and cut, which lets you split a line by tabs or whatever and take some of the fields, and perl which is... Perl... it's an entire programming language but it's also great for one-liners, you can use it like sed
and a whole bunch more
>
yet more infodumping
@Leucrotta @certifiedperson and the beauty of it is you can do this processing on stuff that WASN'T DESIGNED to be processed like that. Which is why the apt package manager has a big disclaimer on its output saying "do not use this in scripts, use apt-get instead, that one has a stable output format". Because if they didn't have that you WOULD get people parsing it to do things. :3 Heck, people probably parse it anyway!
Powershell is completely different. Instead of passing around text, you pass around some kind of structured objects. It's a /very/ Windows way to do things.
The Unix stuff isn't actually restricted to text, by the way. It's arbitrary binary data. The fact that it's text is mostly just convention. Some tools have an option to output JSON so you can have the exact same structured-data thing Powershell does.
yet more infodumping
@Leucrotta @certifiedperson Most programming languages are sequential: do this, then do that, then do the other thing.
Shell (both Unix ones and Powershell) is not.
Shell is fundamentally a /dataflow language./ It's more like node-based visual thingies. Everything happens IN PARALLEL.
(There's a program called "yes" that just produces an infinite stream of 'y's, or whatever string. How does it know when to stop? Maaaagic! Okay no it's not magic it's actually because once the receiving program closes its input, trying to write to a closed pipe fails, and by default kills your program. So "yes | head -n 10" magically only gives you 10 ys.)
yet more infodumping
@Leucrotta @certifiedperson Of course, that only applies per individual set of commands piped together.
You can do that multiple times, of course. Now you have a sequential layer too. And now you have an entire shell script. Scripts are literally just what you would type on the command line, except written out in a file instead.
fuckit I'm gonna explain an entire actual script
@Leucrotta @certifiedperson fuckit I'm just gonna
okay so here's a very simple shell script that's also actually useful; we use it whenever we take a pill!
#!/bin/zsh
if (( $# < 1 )); then
echo 'Usage: medication-add <medication>'
exit
fi
echo "$(date +'%Y-%m-%d %l:%M %p') | $@" >> ~/medications.txt
tail -n 1 ~/medications.txt
...there's kinda a lot to unpack here huh
fuckit I'm gonna explain an entire actual script
@Leucrotta @certifiedperson so first there's the shebang line, the #! bit, which I already infodumped about
when you call a script, e.g. "foo X Y Z", the things you give it are stored in $1, $2, $3, etc. So $1 is X, $2 is Y, $3 is Z.
$# is the /number/ of arguments. The (( )) means "do some math"; so this is checking if there's less than 1 argument. If so, then print how to use the thing and quit.
$() means "run the command inside, and substitute in whatever the command outputs". So "echo $(date a-bunch-of-crap-for-date) $@" ... crap I have to explain $@ now
$* means "put in all of $1, $2, $3, etc."
This works great IF you want them all in a single string (...we should have used $* here! oops!).
If you instead use $@, in double quotes, instead of "$1 $2 $3 ..." it gets substituted as "$1" "$2" "$3" ... . So it's /separate/ things. 90% of the time that's what you want. Not here though, OOPS.
fuckit I'm gonna explain an entire actual script
@Leucrotta @certifiedperson anyway so
"echo $(date) | $@" (the | here is a literal | since it's in quotes, not an actual pipe) outputs something like "2023-11-21 12:27 AM | Advil" (if we ran it with "medication-add Advil")
The >> is redirection. It takes the output of echo, and instead of writing it to the terminal, instead writes it TO A FILE. A single > will completely overwrite the file, but a double >> will just add to it.
So you end up with a file like this:
2023-09-27 2:56 AM | ibuprofen
2023-10-03 11:15 AM | ibuprofen
2023-10-27 11:26 PM | Tums
Perfect!
And then the "tail -n 1 file" bit just prints the last line of the file, so you can see what you added.
@Leucrotta @certifiedperson ... sorry this was probably WAY too much all at once and I'm bad at explaining it and I don't even know if you care anyway. >,,> I just like sharing shit I guess.
re: fuckit I'm gonna explain an entire actual script
@Leucrotta @certifiedperson (the complicated-looking % crap for date is just telling date how its output should be formatted. It's not script syntax.)
slightly less overwhelming example
@Leucrotta @certifiedperson ...for a slightly less overwhelming example
I got those 3 example lines by doing "cat medications.txt | tail -n 3".
cat (meow! actually it's short for 'concatenate') reads whatever file you give it and just prints the output; then tail prints the last few lines.
fuckit I'm gonna explain an entire actual script
@frost @Leucrotta oh fuck me, shell scripts for tracking things is a fantastic idea
fuckit I'm gonna explain an entire actual script
@certifiedperson @Leucrotta *WAGS!* :3 :3 :3
fuckit I'm gonna explain an entire actual script
@frost it's definitely a tad beyond what we can comprehend right now (we'd have to at least write it out to think about what each bit does)
but yeah, keeping that possibility in mind!
re: food, +
@Leucrotta @certifiedperson pfff!