Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Add A Random Quote Every time You Open A Terminal Window

This is the code I put into my `~/.zshrc` file to pull a random quote at the top of my terminal each time I open a new one.

Code

if [ "$(tput cols)" -gt 65 ]; then
    sort -R "/path/to/quotes.txt" | \
    head -1 | \
    sed 's/--/\n    --/' | \
    sed 's/$/\n/' | \
    fold -w 64 -s
else
    sort -R "/path/to/quotes.txt" | \
    head -1 | \
    sed 's/--/\n    --/' | \
    sed 's/$/\n/'                         
fi

### Details

`sort -R FILENAME` randomized the lines in the file and sends them to STDOUT which pipes to:

`head -1` which grabs the first line from the randomized set which pipes to

the `sed` things which split the line out to separate the quote from the author and then add extra line spacing

And then if there are more than 65 columns (as determine by `if [ "$(tput cols)" -gt 65 ]`) then things are piped to:

`fold -w 64 -s`

which wraps lines at 64 characters

The other thing I do is drop an empty file at `~/.hushlogin` which prevents the message of the day from showing up. That way the only thing that shows in the quote.

Quotes are in the format:

Code

Curiouser and curiouser! -- Alice
The death of an old person is like the burning of a library.  -- Traditional
Thank you for your patience during this emergency. -- Tech Support