Over the Easter break I made a little Rust tool for sending toots and/or tweets from a command line. Of course there are dozens of existing tools that enable either of these, but I had a specific use in mind, and also wanted a reasonably small and achievable project to keep learning Rust.
For various reasons I've recently been thinking about the power of "the Unix philosophy", generally summarised as:
- Write programs that do one thing and do it well.
- Write programs to work together.
- Write programs to handle text streams, because that is a universal interface.
My little program takes a text string as input, and sends the same string to the output, the intention being not so much that it would normally be used manually on its own (though it can be) but more that it can "work together" with other programs or scripts. The "one thing" it does (I will leave the question of "well" to other people to judge) is post a tweet and/or toot to social media. It's very much a unidirectional, broadcast tool, not one for having a conversation. In that sense, it's like Whitman's "Barbaric yawp", subject of my favourite scene in Dead Poets Society and a pretty nice description of what social media has become in a decade or so. Calling the program
yawp therefore seemed fitting.
yawp takes text from standard input (
stdin), publishes that text as a tweet and/or a toot, and then prints it to standard output (
stdout). Like I said, it's not particularly complex, and not even all that useful for your daily social media posting needs, but the point is for it to be part of a tool chain. For this reason
yawp takes the configuration it needs to interact with the Mastodon and Twitter APIs from environment (
ENV) variables, because these are quite easy to set programatically and a fairly "universal interface" for setting and getting values to be used in programs.
Here's a simple example of sending a tweet:
yawp 'Hello, World!' -t
We could also send a toot by piping from the
echo program (the
yawp to use
stdin instead of looking for an argument like it uses above):
echo 'Hello again, World!' | yawp - -m
bash, you can send the contents of a file to
stdin, so we could do this too:
yawp - -mt <message.txt
But really the point is to use
yawp to do something like this:
app_that_creates_message | yawp - -mt | do_something_else.sh >> yawping.log
Anyway, enjoy firing your barbaric yawps into the cacophony.