Eliminate /usr/share/dict/words dependency

This commit is contained in:
2024-08-02 21:15:07 -04:00
parent bbf908114c
commit cff0b431f1

View File

@@ -216,7 +216,7 @@ err() { echo "Error: $*" >&2; }
ask_pn() { ask_pn() {
unset PROJECT unset PROJECT
declare -ag ADD_PROJECTS declare -ag ADD_PROJECTS
example_pn="${PROJECT_PREFIX}_$(random_words 3)" example_pn="${PROJECT_PREFIX}_$(random_three_words)"
cat <<-EOF cat <<-EOF
Enter a new or existing project name Enter a new or existing project name
If entering a new project, use the suggested prefix: ${PROJECT_PREFIX}_ If entering a new project, use the suggested prefix: ${PROJECT_PREFIX}_
@@ -245,17 +245,57 @@ ask_pn() {
} }
debug() { (( DEBUG )) && echo "Debug: $*"; } debug() { (( DEBUG )) && echo "Debug: $*"; }
# Not super portable but nice to have # Not super portable but nice to have
random_words() { random_three_words() {
local num=${1:-2}
local -a arr local -a arr
for ((i=0;i<num;i++)); do
word=$(shuf -n1 /usr/share/dict/words | sed -e 's/-//g' -e 's/_//g') adjectives=(
# Sanitize "adorable" "adventurous" "agile" "amazing" "angry" "beautiful" "bold" "brave" "bright" "calm"
word="${word//-/}" "charming" "cheerful" "courageous" "creative" "delicate" "elegant" "energetic" "exciting" "fast" "friendly"
word="${word//_/}" "gentle" "happy" "healthy" "helpful" "honest" "humble" "intelligent" "jovial" "kind" "lively"
word="${word,,}" "lovable" "magnificent" "mellow" "modest" "noble" "outgoing" "passionate" "peaceful" "powerful" "quick"
arr+=("$word") "radiant" "reliable" "resourceful" "respectful" "shy" "smart" "strong" "sweet" "tender" "thoughtful"
done "timid" "unique" "upbeat" "vibrant" "warm" "wise" "wonderful" "youthful" "zealous" "eager"
"friendly" "generous" "imaginative" "independent" "inspired" "joyful" "luminous" "mysterious" "playful" "serene"
"spontaneous" "steady" "spirited" "stylish" "tough" "understanding" "vivid" "zany" "bold" "calm"
"dynamic" "innovative" "proud" "reliable" "sincere" "strong" "talented" "trustworthy" "vivid" "zealous"
)
participles=(
"abandoning" "absorbing" "accelerating" "achieving" "acquiring" "admiring" "advising" "agreeing"
"allowing" "analyzing" "appearing" "applying" "arguing" "assembling" "assisting" "attracting"
"believing" "browsing" "calculating" "calling" "caring" "celebrating" "cleaning" "climbing"
"coaching" "collecting" "combining" "communicating" "competing" "confessing" "considering"
"cooking" "correcting" "creating" "debating" "defining" "delivering" "designing" "discussing"
"driving" "enjoying" "exploring" "feeling" "finishing" "fixing" "forming" "gathering" "growing"
"guiding" "happening" "helping" "hoping" "improving" "increasing" "influencing" "involving"
"learning" "leading" "looking" "managing" "measuring" "moving" "noticing" "observing" "offering"
"organizing" "performing" "preparing" "presenting" "producing" "protecting" "questioning"
"recommending" "recovering" "running" "saving" "searching" "seeing" "sharing" "solving"
"starting" "studying" "succeeding" "supporting" "teaching" "thinking" "understanding" "using"
"validating" "waiting" "working" "writing"
)
animals=(
"antelope" "baboon" "badger" "bat" "bear" "beaver" "bison" "booby" "buffalo" "bull"
"camel" "cat" "cheetah" "chicken" "chimpanzee" "clam" "cobra" "cougar" "cow" "crab"
"crane" "crocodile" "crow" "deer" "dog" "dolphin" "dove" "duck" "eagle" "echidna"
"eel" "elephant" "emu" "falcon" "ferret" "fish" "flamingo" "fox" "frog" "gazelle"
"giraffe" "goat" "goose" "gorilla" "hare" "hawk" "hedgehog" "hippo" "horse" "hyena"
"iguana" "impala" "jaguar" "kangaroo" "koala" "lion" "llama" "lobster" "lynx" "macaw"
"manatee" "mole" "monkey" "moose" "mouse" "mule" "octopus" "okapi" "opossum" "ostrich"
"otter" "owl" "panda" "panther" "parrot" "penguin" "pig" "platypus" "porcupine" "quail"
"rabbit" "rat" "raven" "reindeer" "rhinoceros" "robin" "salmon" "seal" "shark" "sheep"
"shrimp" "skunk" "sloth" "snail" "snake" "sparrow" "spider" "squid" "squirrel" "starling"
"stingray" "swan" "tapir" "tiger" "toad" "toucan" "turtle" "vulture" "walrus" "wolverine"
"wolf" "wombat" "zebra"
)
arr+=(
"$(shuf -n1 -e "${adjectives[@]}")"
"$(shuf -n1 -e "${participles[@]}")"
"$(shuf -n1 -e "${animals[@]}")"
)
printf "%s_" "${arr[@]}" | sed 's/_$//' printf "%s_" "${arr[@]}" | sed 's/_$//'
} }
# @description Backup one or more files to an incremented .bk file # @description Backup one or more files to an incremented .bk file
@@ -306,8 +346,12 @@ interactive_header() {
echo "This script uses a local R library at $HOME/R/$SCRIPT_NAME" echo "This script uses a local R library at $HOME/R/$SCRIPT_NAME"
echo "You can install the R dependencies to this library using the install_dependencies module" echo "You can install the R dependencies to this library using the install_dependencies module"
if ((YES)) || ask "Would you like to make this library the default for your user?"; then if ((YES)) || ask "Would you like to make this library the default for your user?"; then
echo "Adding R_LIBS_USER=$HOME/R/$SCRIPT_NAME to your .bashrc" line="export R_LIBS_USER=$HOME/R/$SCRIPT_NAME"
echo "export R_LIBS_USER=$HOME/R/$SCRIPT_NAME" >> "$HOME/.bashrc" if ! grep -qF "$line" ~/.bashrc; then
echo "Adding $line to your .bashrc"
echo "If you use a different shell, update your R_LIBS_USER environment variable accordingly"
echo "$line" >> ~/.bashrc
fi
fi fi
else else
debug "R_LIBS_USER already set to $HOME/R/$SCRIPT_NAME" debug "R_LIBS_USER already set to $HOME/R/$SCRIPT_NAME"