Marty Oehme
a08f2daafe
Added quick way to translate from anywhere with the Mod+Shift+T mapping. Will open a bemenu window into which text to be translated can be input (as well as any translation options) and will return in another bemenu window. From there, selected text can be put on the clipboard for easy pasting. Internally uses a simple wrapper script for translate-shell on which the translation is based. Closes #12.
41 lines
1.1 KiB
Bash
Executable file
41 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# bemenu-translate
|
|
|
|
# A very simple bemenu wrapper script for translate-shell.
|
|
#
|
|
# Displays a bemenu into which user can enter their phrase
|
|
# and any options they want to pass to translate-shell.
|
|
# Subsequently opens a second prompt with the results.
|
|
# If phrase is entered and then Alt+1 instead of Enter pressed
|
|
# will show the 'brief', often only one-word single-translation
|
|
# results instead.
|
|
#
|
|
# Some useful commandline options for translate shell are e.g.:
|
|
# `de: Wort` -> to translate 'from' German
|
|
# `:es horse` -> to translate 'to' Spanish
|
|
# and both can be combined as well `de:es Pferd`.
|
|
# But of course many more possibilities exist, see
|
|
# translate-shell help.
|
|
|
|
input=$(echo " " | bemenu -p "Alt+1 for brief mode| Translate>")
|
|
exit_code="$?"
|
|
|
|
if [ -z "$input" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
case "$exit_code" in
|
|
1) exit 0 ;;
|
|
0)
|
|
output=$(echo "$input" | xargs trans -j -no-ansi)
|
|
;;
|
|
10)
|
|
output=$(echo "$input" | xargs trans -j -no-ansi -b)
|
|
;;
|
|
esac
|
|
|
|
chosen=$(echo "$output" | bemenu -p "Translation:" -w -l 100)
|
|
|
|
if [ -n "$chosen" ] && exist clip; then
|
|
clip "$chosen"
|
|
fi
|