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:
parent
4abfc41ca2
commit
a08f2daafe
3 changed files with 74 additions and 29 deletions
|
@ -249,6 +249,7 @@ toilet free replacement for the FIGlet utility. A
|
||||||
tomb Crypto Undertaker, a simple tool to manage encrypted storage R
|
tomb Crypto Undertaker, a simple tool to manage encrypted storage R
|
||||||
toot a Mastodon CLI client A
|
toot a Mastodon CLI client A
|
||||||
topgrade Invoke the upgrade procedure of multiple package managers R
|
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
|
transmission-qt Fast, easy, and free BitTorrent client (Qt GUI) R
|
||||||
ttf-brill Brill Typeface by John Hudson for Brill Publishing House A
|
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
|
ttf-comic-neue Comic Neue aspires to be the casual script choice for everyone including the typographically savvy. A
|
||||||
|
|
|
41
scripts/.local/bin/bemenu-translate
Executable file
41
scripts/.local/bin/bemenu-translate
Executable 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
|
|
@ -59,6 +59,9 @@ riverctl map normal $mod+Shift R spawn "$term --class float -e qalc"
|
||||||
# Open emoji picker
|
# Open emoji picker
|
||||||
riverctl map normal $mod+Shift E spawn "bemoji -t"
|
riverctl map normal $mod+Shift E spawn "bemoji -t"
|
||||||
|
|
||||||
|
# Open translation helper
|
||||||
|
riverctl map normal $mod+Shift T spawn "bemenu-translate"
|
||||||
|
|
||||||
# Desktop theming
|
# Desktop theming
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
riverctl map normal $mod+Shift S spawn 'styler set $(styler list themes | bemenu)'
|
riverctl map normal $mod+Shift S spawn 'styler set $(styler list themes | bemenu)'
|
||||||
|
|
Loading…
Reference in a new issue