-
Notifications
You must be signed in to change notification settings - Fork 3
/
rofi_et_mode
executable file
·175 lines (135 loc) · 4.49 KB
/
rofi_et_mode
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/sh
copy_to_clipboard () {
if [[ -z "$XDG_SESSION_TYPE" ]]; then
SESSION_TYPE=$(loginctl show-session "$(loginctl | grep $(whoami) | awk '{ print $1 }')" -p Type --value)
else
SESSION_TYPE="$XDG_SESSION_TYPE"
fi
if [[ "$SESSION_TYPE" == "wayland" ]]; then
echo -n "$1" | wl-copy
else
echo -n "$1" | xclip -r -selection clipboard
fi
}
usage () {
cat << EOF
<u>Usage (in rofi's or dmenu's input bar)</u>:
COMMAND [WORD]
<u>Commands</u>:
<b><i>abr</i></b>, <b><i>abbreviations <word></i></b>
Get what <word> might stand for from abbreviations.com.
<b><i>ant</i></b>, <b><i>antonyms <word></i></b>
Get antonyms for <word> from bighugelabs.com.
<b><i>def</i></b>, <b><i>define <word></i></b>
Get definitions for <word> from wordnik.com if correctly spelled, otherwise display spell suggestions.
<b><i>pro</i></b>, <b><i>pronounce <word></i></b>
Play pronunciation of <word> from wordnik.com and dictionaryapi.dev.
<b><i>spl</i></b>, <b><i>spell <word></i></b>
Get spell suggestions for <word> from wordlist if not spelled correctly, otherwise display a message indicating that <word> is spelled correctly.
<b><i>syn</i></b>, <b><i>synonyms <word></i></b>
Get synonyms for <word> from bighugelabs.com.
<b><i>help</i></b>
Display this help message
EOF
}
get_abbreviations () {
ABBREVIATIONS=$(et -abr "$1")
echo -en "\0message\x1f<b><i>What \"$1\" might stand for:</i></b>\n"
echo "$ABBREVIATIONS"
}
get_antonyms () {
spell $1 0
ANTONYMS=$(et -ant "$1")
echo -en "\0message\x1f<b><i>Antonyms for \"$1\":</i></b>\n"
echo "$ANTONYMS"
}
define () {
spell $1 0
DEFINITIONS=$(et -def "$1")
echo -en "\0message\x1f<b><i>Definitions for \"$1\":</i></b>\n"
echo "$DEFINITIONS"
}
pronounce () {
WORD="$1"
spell "$WORD" 0
SOURCES=$(et -lst "$WORD" | sed 's/^- //')
if [[ $(echo "$SOURCES" | wc -l) -gt 1 ]]; then
echo -en "\0data\x1fpro|$WORD\n"
echo -en "\0message\x1f<b><i>Choose pronunciation source/accent: </i></b>\n"
echo "$SOURCES"
else
et -pro "$WORD" -src 'macmillan'
exit 0
fi
}
spell () {
SUGGESTIONS=$(et -spl "$1")
FOUND=$?
SHOW_MESSAGE=$2
if [ $FOUND -eq 0 ]; then
if [ $SHOW_MESSAGE -eq 1 ]; then
echo -en "\0markup-rows\x1ftrue\n"
echo -en "<span foreground=\"green\">\"$1\" appears to be spelled correctly</span>\n"
fi
else
echo -en '\0data\x1ftrue\n'
echo -en '\0delim\x1f\r\n'
echo -en "\0message\x1f<span foreground=\"red\">\"$1\" doesn't appear to be spelled correctly.</span>\n<b><i>Suggestions:</i></b>\r"
echo "$SUGGESTIONS" | tr '\n' '\r'
exit 1
fi
}
get_synonyms () {
spell $1 0
SYNONYMS=$(et -syn "$1")
echo -en "\0message\x1f<b><i>Synonyms for \"$1\":</i></b>\n"
echo "$SYNONYMS"
}
if [ "$ROFI_DATA" == "true" ]; then
echo -en '\0delim\x1f\n\r'
echo -en '\0data\x1ffalse\n'
fi
if [ "$ROFI_RETV" == 1 ]; then
if [[ "$(echo "$ROFI_DATA" | cut -d '|' -f 1)" == "pro" ]]; then
SOURCE="$(echo "$@" | sed 's/ (default)$//')"
WORD="$(echo "$ROFI_DATA" | cut -d '|' -f 2)"
et -pro "$WORD" -src "$SOURCE"
else
copy_to_clipboard "$@"
notify-send -a "rofi_et" "\"$@\" has been copied to clipboard"
fi
exit 0
fi
echo -en '\0message\x1f\n'
if [ "$@" ]; then
COMMAND=$(echo "$@" | cut -d " " -f 1)
WORD=$(echo "$@" | cut -d " " -f 2)
if [ "$COMMAND" == "help" ]; then
echo -en "\0markup-rows\x1ftrue\n"
usage
else
SPACE_COUNT=$(echo "$@" | tr -cd " \t" | wc -c)
if [ "$WORD" == "" ] || [ $SPACE_COUNT -lt 1 ]; then
echo -en "\0markup-rows\x1ftrue\n"
echo '<span foreground="red">You need to specifiy a command and a word</span>'
else
echo -en "\0markup-rows\x1ffalse\n"
if [ "$COMMAND" == "abr" ] || [ "$COMMAND" == "abbreviations" ]; then
get_abbreviations $WORD
elif [ "$COMMAND" == "ant" ] || [ "$COMMAND" == "antonyms" ]; then
get_antonyms $WORD
elif [ "$COMMAND" == "def" ] || [ "$COMMAND" == "define" ]; then
define $WORD
elif [ "$COMMAND" == "pro" ] || [ "$COMMAND" == "pronounce" ]; then
pronounce $WORD
elif [ "$COMMAND" == "spl" ] || [ "$COMMAND" == "spell" ]; then
spell $WORD 1
elif [ "$COMMAND" == "syn" ] || [ "$COMMAND" == "synonyms" ]; then
get_synonyms $WORD
else
echo -en "\0markup-rows\x1ftrue\n"
echo "<span foreground=\"red\">Unkown command \"$COMMAND\"</span>"
fi
fi
fi
fi