-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefine-selected
executable file
·40 lines (31 loc) · 1.23 KB
/
define-selected
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
#!/usr/bin/env fish
# define-selected - Define the specified or selected word, showing the result in a popup dialog.
# Requirements: dictd, xclip, text-gui (part of defaultxr/scripts)
# See also: translate-selected
set -- script "$(path basename (status filename))"
argparse -n "$script" --ignore-unknown 'h/help' -- $argv
if set -q _flag_h
echo "$script - Define the specified or selected word, showing the result in a popup dialog."
echo "Usage: $script [arguments] [word]"
echo
echo " -h/--help - Print help and exit."
exit
end
if test (count $argv) -gt 0
set word "$argv[1]"
else
set word "$(xclip -o -selection primary)"
end
set notification_id (notify-send --print-id --urgency=low --expire-time=10000 "$script" "Looking up \"$word\"...")
set title "\"$word\" definition"
set definition "$(dict "$word" 2>/tmp/$script-err.txt | tail -n +5 | string collect)"
if test -z "$definition"
set title "Error"
set definition "$(cat /tmp/$script-err.txt)"
end
notify-send --replace-id="$notification_id" --urgency=low --expire-time=1 "Found definition."
if command -qs text-gui
text-gui -T "$title" --text="$definition"
else
zenity --info --width=800 --title="\"$word\" definition" --text="$definition"
end