diff options
author | Case Duckworth | 2022-07-10 18:32:12 -0500 |
---|---|---|
committer | Case Duckworth | 2022-07-10 18:32:12 -0500 |
commit | 08661ecb1aaccc7077a03cf43011432c8db8ee17 (patch) | |
tree | cf79caacdc0235b3162478006908eb4961a099f9 | |
parent | Add usage() (diff) | |
download | thesauracles-main.tar.gz thesauracles-main.zip |
-rwxr-xr-x | thesauracles | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/thesauracles b/thesauracles index 4812eb4..218cf88 100755 --- a/thesauracles +++ b/thesauracles | |||
@@ -63,31 +63,51 @@ query() { | |||
63 | } | 63 | } |
64 | 64 | ||
65 | random_word() { | 65 | random_word() { |
66 | n="$(wc -l <"$wf")" | 66 | sort -Ru "$wf" | head -n1 |
67 | ln="$((RANDOM % n + 1))" | ||
68 | sed -n ${ln}p "$wf" | ||
69 | } | 67 | } |
70 | 68 | ||
71 | main() { | 69 | main() { |
70 | degree=6 # the Kevin Bacon number ;) | ||
71 | talkative=true | ||
72 | |||
73 | while getopts hqc:s:t:h: opt; do | ||
74 | case "$opt" in | ||
75 | h) usage ;; | ||
76 | q) talkative=false ;; | ||
77 | c) degree="$OPTARG" ;; | ||
78 | s) dict_server="$OPTARG" ;; | ||
79 | t) dict_database="$OPTARG" ;; | ||
80 | l) thesaurus_header_lines="$OPTARG" ;; | ||
81 | *) usage 1 ;; | ||
82 | esac | ||
83 | done | ||
84 | shift $((OPTIND - 1)) | ||
85 | |||
72 | word="$1" | 86 | word="$1" |
73 | words=() | 87 | words=() |
74 | hopn=0 | 88 | hopn=0 |
75 | while [ "$hopn" -lt "$hops" ]; do | 89 | while [ "$hopn" -lt "$degree" ]; do |
90 | #printf '%s ' "$hopn" | ||
76 | if query "$word"; then | 91 | if query "$word"; then |
77 | echo "$word..." | 92 | $talkative && echo "$word..." >&2 |
78 | words+=("$word") | 93 | words+=("$word") |
79 | word="$(random_word)" | 94 | word="$(random_word)" |
80 | : $((hopn++)) | 95 | : $((hopn++)) |
81 | elif [ "$hopn" -eq 0 ]; then | 96 | elif [ "$hopn" -eq 0 ]; then |
82 | echo "Oops, don't know \"$word!\"" >&2 | 97 | echo "Oops, don't know \"$word!\"" >&2 |
83 | exit 1 | 98 | exit 2 |
84 | else | 99 | else |
85 | echo "hmm." | 100 | $talkative && echo "hmm." >&2 |
86 | : $((hopn--)) | 101 | : $((hopn--)) |
87 | word="${words[-1]}" | 102 | word="${words[-1]}" |
88 | fi | 103 | fi |
89 | done | 104 | done |
90 | echo "$word" | awk '{print "> " toupper($0) "!"}' | 105 | echo "$word" | |
106 | if $talkative; then | ||
107 | awk '{print "> " toupper($0) "!"}' | ||
108 | else | ||
109 | cat | ||
110 | fi | ||
91 | } | 111 | } |
92 | 112 | ||
93 | if [[ "$BASH_SOURCE" = "$0" ]]; then | 113 | if [[ "$BASH_SOURCE" = "$0" ]]; then |