22
22
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
# SOFTWARE.
24
24
25
- # Print out synonyms.
25
+ # Finds synonyms for a given word in a specified language .
26
26
#
27
27
# Dependencies: jq
28
28
#
31
31
set -e
32
32
33
33
self=${0##*/ }
34
- version=" $self v1.4.2"
34
+ version=" $self v1.4.3"
35
+
36
+ _help () {
37
+ cat << EOF
38
+ Usage: $self [OPTION] WORD
39
+
40
+ Finds synonyms for a given word in a specified language.
41
+ Run $self -i for more information.
42
+
43
+ Options:
44
+ -l LANG Finds all synonyms for this specific language.
45
+ Languages supported: en, fr, cs, el, es, da, de,
46
+ hu, it, no, pl, pt, ro, ru, sk
47
+ -h Show help message and exit.
48
+ -i Show more help information and exit.
49
+ -v Show program version number and exit.
50
+
51
+ EOF
52
+ }
35
53
36
54
_info () {
37
55
cat << EOF
@@ -42,6 +60,7 @@ List of languages supported: en, fr, cs, el, es, da, de, hu, it,
42
60
no, pl, pt, ro, ru, sk
43
61
44
62
Requirements to run $self :
63
+ ============================
45
64
46
65
- Thesaurus API key from https://thesaurus.altervista.org/mykey
47
66
- jq https://stedolan.github.io/jq/download/
@@ -57,6 +76,7 @@ In this file, you can chose a default language and you will need
57
76
to input your API key.
58
77
59
78
.synonymrc example:
79
+ ===================
60
80
61
81
# API KEY from https://thesaurus.altervista.org/mykey
62
82
SYNONYM_THESAURUS_KEY=<API KEY>
@@ -67,35 +87,22 @@ to input your API key.
67
87
# it, no, pl, pt, ro, ru, sk
68
88
SYNONYM_SEARCH_LANG=en
69
89
70
- Note:
90
+ Notes:
91
+ ======
71
92
72
93
If no language is set in .synonymrc, or specified in parameters,
73
94
the default language will be fetched from the os (\$ LANGUAGE or
74
95
\$ LANG). If not supported, or null, it will be set as default to
75
96
en_US.
76
97
98
+ ---
99
+
77
100
Copyright 2020 Matthieu Petiteau, all rights reserved.
78
101
$version
79
102
80
103
EOF
81
104
}
82
105
83
- _usage () {
84
- cat << EOF
85
- Usage: $self [OPTION] WORD
86
- Finds all synonyms for a specific word in a specified language.
87
-
88
- Options:
89
- -l LANG Finds all synonyms for this specific language.
90
- Languages supported: en, fr, cs, el, es, da, de,
91
- hu, it, no, pl, pt, ro, ru, sk
92
- -h Show help message and exit.
93
- -u Show usage and exit.
94
- -v Show program version number and exit.
95
-
96
- EOF
97
- }
98
-
99
106
# Compute response from the API.
100
107
_compute () {
101
108
# Check for any erros.
@@ -165,7 +172,7 @@ _language_index() {
165
172
* )
166
173
printf ' %s\n%s\n' \
167
174
" Error: Language $1 not supported." \
168
- " Run $self -u for usage and see the list of supported languages." >&2
175
+ " Run $self -i for more information and see the list of supported languages." >&2
169
176
exit 1
170
177
;;
171
178
esac
@@ -205,8 +212,8 @@ _init() {
205
212
done
206
213
207
214
printf ' %s\n%s\n' \
208
- ' Error: synonymrc file not found' \
209
- " Run $self -h for help ." >&2
215
+ ' Error: . synonymrc file not found. ' \
216
+ " Run $self -i for setup information ." >&2
210
217
exit 1
211
218
}
212
219
@@ -219,19 +226,19 @@ command -v jq >/dev/null 2>&1 || {
219
226
}
220
227
221
228
# Params
222
- options=" :l:huv "
229
+ options=" :l:hiv "
223
230
while getopts " $options " option; do
224
231
case " $option " in
225
232
l)
226
233
_synonym_language=$( _language_index " $OPTARG " )
227
234
;;
228
235
h)
229
- _info
230
- _usage
236
+ _help
231
237
exit 0
232
238
;;
233
- u)
234
- _usage
239
+ i)
240
+ _info
241
+ _help
235
242
exit 0
236
243
;;
237
244
v)
@@ -240,7 +247,7 @@ while getopts "$options" option; do
240
247
;;
241
248
\? )
242
249
printf ' Error: invalid option: -%s\n' " $OPTARG " >&2
243
- _usage
250
+ _help
244
251
exit 1
245
252
;;
246
253
esac
@@ -251,15 +258,14 @@ _searched_word="$1"
251
258
_init
252
259
253
260
[[ -z $_searched_word ]] && {
254
- printf ' %s\n%s\n' \
255
- ' Error: Missing word to search.' \
256
- " Run $self -u for usage." >&2
261
+ printf ' Error: Missing word to search.\n' >&2
262
+ _help
257
263
exit 1
258
264
}
259
265
[[ -z $SYNONYM_THESAURUS_KEY ]] && {
260
266
printf ' %s\n%s\n' \
261
- ' Error: api key not found in synonymrc.' \
262
- " Run $self -h for help ." >&2
267
+ ' Error: API key not found in synonymrc.' \
268
+ " Run $self -i for setup information ." >&2
263
269
exit 1
264
270
}
265
271
[[ -z $_synonym_language ]] && _synonym_language=" $( _get_language) "
0 commit comments