-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefine
More file actions
executable file
·51 lines (44 loc) · 1.8 KB
/
define
File metadata and controls
executable file
·51 lines (44 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# define - command line dictionary
# Program name from it's filename
prog=${0##*/}
# Text color variables
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldwht=${txtbld}$(tput setaf 7) # white
txtrst=$(tput sgr0) # Reset
warn=${bldred}!${txtrst}
sedbldwht='\c[[1;37m' # Sed white - bold
sedtxtrst='\c[[0m' # text reset
# Display usage if full argument isn't given
if [[ -z "$@" ]]; then
echo " $prog <word-to-lookup> - command line dictionary"
exit
fi
# Suggest possible words if not in dictionary, otherwise define
wordchecknum=$(echo "$1" | aspell -a | sed '1d' | wc -m)
wordcheckprnt=$(echo "$1" | aspell -a | sed '1d' | sed 's/^.*: //')
if [[ $wordchecknum -gt "3" ]]; then
echo -e "$warn ${bldwht}"$1"${txtrst} is not in the dictionary. Possible alternatives:"
echo -e "\n$wordcheckprnt" | fmt -w 76 | sed 's/^/ /g'
echo
exit
fi
# Lookup word and reformat/highlight
sdcv $1 | \
# lookup, delete extrenous first lines, delete last empty line
sed '1,3d' | sed '/^*$/d' | \
# print more obvious word type
sed "h; :b; \$b ; N; /^${1}\n n/ {h;x;s// ${sedbldwht}Noun${sedtxtrst}\n/; bb}; \$b ; P; D" | \
sed "h; :b; \$b ; N; /^ v/ {h;x;s// ${sedbldwht}Verb${sedtxtrst}\n/; bb}; \$b ; P; D" | \
sed "h; :b; \$b ; N; /^ adv/ {h;x;s// ${sedbldwht}Adverb${sedtxtrst}\n/; bb}; \$b ; P; D" | \
sed "h; :b; \$b ; N; /^ adj/ {h;x;s// ${sedbldwht}Adjective${sedtxtrst}\n/; bb}; \$b ; P; D" | \
# reformat to left (ok, there's gotta be a better way to do this)
sed 's/^ / /g' | \
sed 's/^ / /g' | \
sed 's/^ / /g' | \
sed 's/^ / /g' | \
# rename single entry for conformity
sed 's/^ : / 1: /g' | sed "/^${1}.*/d" | sed "s/^ \[/ \[/g" | \
# and coloring
sed "s/${1}/${sedbldwht}${1}${sedtxtrst}/g"