-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththerofisaurus.sh
More file actions
executable file
·50 lines (38 loc) · 1.33 KB
/
Copy paththerofisaurus.sh
File metadata and controls
executable file
·50 lines (38 loc) · 1.33 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
#!/usr/bin/env bash
readonly t_file=$HOME/projects/the-rofi-saurus/thesaurus.txt
escape_key="Escape"
exit_key="Alt+q"
start_key="Alt+a"
emph_color="#FF79C6"
menu="Press <span color='${emph_color}'>${exit_key}</span> or \
<span color='${emph_color}'>Escape</span> to exit
Press <span color='${emph_color}'>${start_key}</span> to restart"
do_rofi="rofi -kb-custom-1 ${exit_key} -kb-custom-2 ${start_key} -dmenu -p"
function check_output() {
local code=${1}
local result=${2}
if [[ ${code} -eq 10 ]]; then # exit_key was pressed
exit
elif [[ ${code} -eq 11 ]]; then # start_key was pressed
return 1
elif [[ ${code} -ne 0 ]]; then # other codes are for errors
exit
fi
if [[ -z ${result} ]]; then
exit
fi
return 0
}
while :; do
word=$(${do_rofi} "Enter a single word" -mesg "${menu}")
check_output $? ${word} || continue
result=$(tail -n +2 "${t_file}" | grep -w "${word}")
if [[ -z "${result}" ]]; then
rofi -e "No entries found for '${word}' (press <Enter> to continue)"
continue
fi
result=$(echo "${result}" | ${do_rofi} "Select line to expand" -mesg "${menu}")
check_output $? ${result} || continue
result=$(echo ${result} | tr " " "\n" | ${do_rofi} "Results (${word})" -mesg "${menu}")
check_output $? ${result} || continue
done