It’s been a busy week, and I’ll be writing up my WWDC thoughts and a couple of TUAW posts after a plane ride today. In the meantime, I made you a thing.
This quick function is part of a script I wrote to generate multiple files filled with random Markdown lipsum with an index for Marked testing.
Numbered files are boring, and truly random character sequences aren’t much fun. Aspell has a master dictionary that happens to contain a lot of potentially funny words. I decided to dump those and randomly pick two to string together as filenames.
The function uses a dictionary file (single word per line) and shuf, available through Homebrew in the Gnu coreutils package (brew install coreutils). You can create a dictionary file using Aspell (brew install aspell) with the command aspell dump master > dictionary.txt (or just grab the one I made). Be sure to edit the “wordfile” variable in the function to point to the location of your dictionary.
# Bash function gen_random_filename# Description: Generates random two-word names# Requires a dictionary file, easily generated with `aspell dump master > dictionary.txt`# or grab it from https://gist.githubusercontent.com/ttscoff/55493fe89c35ec1588ba/raw/# Requires shuf (brew install coreutils)## Example results:# darkest_pickpockets# besets_struts# unzip_Malonegen_random_filename(){localwordfile=~/words/dictionary.txt
localrandwords
localtitle
if[[$(whichshuf)]];thenrandwords=`shuf-n2$wordfile|sed's/[^a-zA-Z]//g'`title=`echo$randwords|tr' ''_'`elsecat<<-EOS $FUNCNAME requires the utility shuf (or gshuf) to generate random names. Use homebrew to install "coreutils," which includes shuf. EOSreturnfiecho$title}