river: Add translation widget mapping

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.
This commit is contained in:
Marty Oehme 2022-05-02 16:08:30 +02:00
parent 4abfc41ca2
commit a08f2daafe
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
3 changed files with 74 additions and 29 deletions

View File

@ -249,6 +249,7 @@ toilet free replacement for the FIGlet utility. A
tomb Crypto Undertaker, a simple tool to manage encrypted storage R
toot a Mastodon CLI client A
topgrade Invoke the upgrade procedure of multiple package managers R
translate-shell A command-line interface and interactive shell for Google Translate R
transmission-qt Fast, easy, and free BitTorrent client (Qt GUI) R
ttf-brill Brill Typeface by John Hudson for Brill Publishing House A
ttf-comic-neue Comic Neue aspires to be the casual script choice for everyone including the typographically savvy. A

1 Name Description Source Target
249 tomb Crypto Undertaker, a simple tool to manage encrypted storage R
250 toot a Mastodon CLI client A
251 topgrade Invoke the upgrade procedure of multiple package managers R
252 translate-shell A command-line interface and interactive shell for Google Translate R
253 transmission-qt Fast, easy, and free BitTorrent client (Qt GUI) R
254 ttf-brill Brill Typeface by John Hudson for Brill Publishing House A
255 ttf-comic-neue Comic Neue aspires to be the casual script choice for everyone including the typographically savvy. A

View File

@ -0,0 +1,41 @@
#!/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

View File

@ -59,6 +59,9 @@ riverctl map normal $mod+Shift R spawn "$term --class float -e qalc"
# Open emoji picker
riverctl map normal $mod+Shift E spawn "bemoji -t"
# Open translation helper
riverctl map normal $mod+Shift T spawn "bemenu-translate"
# Desktop theming
# shellcheck disable=SC2016
riverctl map normal $mod+Shift S spawn 'styler set $(styler list themes | bemenu)'