-
-
Save thapakazi/fd67475a2098342c27a5 to your computer and use it in GitHub Desktop.
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 with date appended | |
# 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 and aspell | |
# | |
# Example results: | |
# reissue_degraded-2015-03-12@0254 | |
# Cascades_derivatives-2015-03-12@0255 | |
# oxygens_soaked-2015-03-12@0256 | |
# leaderships_neutralized-2015-03-12@0306 | |
DICT_FILE=dictionary.txt | |
DATE_APPEND=${1-yes} | |
check_pkgs(){ | |
if [[ ! $(which shuf) ]] && [[ ! $(which aspell) ]] ; then | |
cat <<-EOS | |
$FUNCNAME requires the utilities: | |
aspell :to generate random names | |
shuf (or gshuf) :to shuffle words | |
... please install them first. | |
pkg_name: coreutils, aspell | |
EOS | |
fi | |
} | |
populate_dict(){ | |
if [ ! -f $DICT_FILE ]; then | |
echo 'generating dictionary file to shuffle' | |
aspell dump master > dictionary.txt | |
fi | |
} | |
gen_random_name() { | |
local randwords | |
local title | |
randwords=`shuf -n 2 $DICT_FILE|sed 's/[^a-zA-Z]//g'` | |
title=`echo $randwords|tr ' ' '_'` | |
if [ "$DATE_APPEND" = yes ]; then | |
echo $title-$(date +'%F@%I%M') | |
else | |
echo $title | |
fi | |
} | |
check_pkgs | |
populate_dict | |
gen_random_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment