Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Last active August 29, 2015 14:02
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ttscoff/2bf47bae1807e87650bb to your computer and use it in GitHub Desktop.
Bash function to generate random 2-word underscore strings for filenames. Uses aspell and shuf (gnu coreutils).
# 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_Malone
gen_random_filename() {
local wordfile=~/words/dictionary.txt
local randwords
local title
if [[ $(which shuf) ]]; then
randwords=`shuf -n 2 $wordfile|sed 's/[^a-zA-Z]//g'`
title=`echo $randwords|tr ' ' '_'`
else
cat <<-EOS
$FUNCNAME requires the utility shuf (or gshuf) to generate random names.
Use homebrew to install "coreutils," which includes shuf.
EOS
return
fi
echo $title
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment