blob: 137011ae06fe5f370d4b7facb1efd3d3ec3a1d00 (
plain) (
blame)
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/sh
## dict.sh - nicely look up words in dictionaries with dictd
## Configuration
pager="rofi -location 2 -width -81 -e"
## Error codes
NO_TERM_PROVIDED=4
NO_DICT_PROVIDED=5
## Get available dictionaries
get_dict() {
dict -D | \
tail -n +2 | \
grep -v "fd" | \
sed 's/^ [a-z0-9-]* *//' | \
dmenu -i -p "Dictionary"
}
## Get search term
get_search_term() {
term=$(printf "Clipboard\nPrimary selection\n" | dmenu -i -p "Search term")
if [ "$term" = "Clipboard" ]; then
echo "$(xclip -o -selection clipboard)"
elif [ "$term" = "Primary selection" ]; then
echo "$(xclip -o -selection primary)"
else
echo "$term"
fi
}
## Search dictionary for term
search() {
dict=$1
term=$2
dict -d $(dict -D | grep "$dict" | cut -w -f2) "$term"
}
## Main
dict=$(get_dict)
[ -z "$dict" ] && exit $NO_DICT_PROVIDED
term=$(get_search_term)
[ -z "$term" ] && exit $NO_TERM_PROVIDED
result=$(search "$dict" "$term")
[ -z "$result" ] && $pager "No results found." || $pager "$result"
|