qutebrowser: Fix git tracking, Add translate script
Added script to quickly translate a page or selected text through google translate. Can be invoked through the aliases `:translate-page` or `:translate-selection` respectively, or the shortcuts <leader>bg, <leader>bG. Added some gitignore files in the directory to stop keeping track of non-personal configuration files.
This commit is contained in:
parent
bc534e2026
commit
845b98d22d
5 changed files with 83 additions and 15 deletions
51
qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh
Executable file
51
qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env sh
|
||||
#
|
||||
# Translate the page, or if `--text` argument is given the current selection, with google translate.
|
||||
#
|
||||
# Adapted code from https://github.com/AckslD/Qute-Translate, with much gratitude.
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
-s | --source)
|
||||
QUTE_TRANS_SOURCE=$2
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-t | --target)
|
||||
QUTE_TRANS_TARGET=$2
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
--url)
|
||||
QUTE_TRANS_URL="true"
|
||||
shift
|
||||
;;
|
||||
--text)
|
||||
QUTE_TRANS_URL="false"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$QUTE_TRANS_SOURCE" ]; then
|
||||
# Default use automatic language for source
|
||||
QUTE_TRANS_SOURCE="auto"
|
||||
fi
|
||||
if [ -z "$QUTE_TRANS_TARGET" ]; then
|
||||
# Default use English for target
|
||||
QUTE_TRANS_TARGET="en"
|
||||
fi
|
||||
|
||||
if [ "$QUTE_TRANS_URL" = "false" ]; then
|
||||
# Translate selected text
|
||||
PAGE="https://translate.google.com/#view=home&op=translate&"
|
||||
CONT_KEY="text"
|
||||
CONTENT=$QUTE_SELECTED_TEXT
|
||||
else
|
||||
# Default translate URL
|
||||
PAGE="https://translate.google.com/translate?"
|
||||
CONT_KEY="u"
|
||||
CONTENT=$QUTE_URL
|
||||
fi
|
||||
|
||||
echo "open -t ${PAGE}sl=$QUTE_TRANS_SOURCE&tl=$QUTE_TRANS_TARGET&$CONT_KEY=$CONTENT" >>"$QUTE_FIFO"
|
||||
Loading…
Add table
Add a link
Reference in a new issue