Last active
August 29, 2015 14:02
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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