From 845b98d22dc9fa52a28e11f0ff824e7b3715afff Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 13 Nov 2020 09:34:52 +0100 Subject: [PATCH] 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 bg, bG. Added some gitignore files in the directory to stop keeping track of non-personal configuration files. --- .gitignore | 3 ++ qutebrowser/.config/qutebrowser/config.py | 21 +++++--- qutebrowser/.config/qutebrowser/quickmarks | 23 +++++---- .../qutebrowser/stylesheets/stylesheet.css | 0 .../userscripts/translate_google.sh | 51 +++++++++++++++++++ 5 files changed, 83 insertions(+), 15 deletions(-) delete mode 100644 qutebrowser/.config/qutebrowser/stylesheets/stylesheet.css create mode 100755 qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh diff --git a/.gitignore b/.gitignore index 8bd317e..f551fa5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,9 @@ sponsorblock.txt # ignore any just-in-time settings that took place in qutebrowser qutebrowser/.config/qutebrowser/autoconfig.yml +qutebrowser/.config/qutebrowser/qsettings +qutebrowser/.config/qutebrowser/bookmarks +qutebrowser/.config/qutebrowser/stylesheets # ignore vifm & ueberzug utility files vifm-help.txt diff --git a/qutebrowser/.config/qutebrowser/config.py b/qutebrowser/.config/qutebrowser/config.py index 5101070..4fd3b85 100644 --- a/qutebrowser/.config/qutebrowser/config.py +++ b/qutebrowser/.config/qutebrowser/config.py @@ -31,22 +31,23 @@ js_whitelist = [ "*://*.youtube.com/*", "*://127.0.0.1/*", "*://asciinema.org/*", + "*://calendar.google.com/*", + "*://clockify.me/tracker*", "*://darksky.net/*", "*://deepl.com/*", "*://duckduckgo.com/*", + "*://fosstodon.org/*", "*://github.com/*", "*://gitlab.com/*", "*://localhost/*", - "*://fosstodon.org/*", "*://mail.google.com/*", "*://maps.google.com/*", + "*://*.martyoeh.me/*" "*://news.ycombinator.com/*", "*://old.reddit.com/*", "*://todoist.com/*", "*://toggl.com/*", - "*://clockify.me/tracker*", "*://translate.google.com/*", - "*://calendar.google.com/*", "chrome://*/*", "file://*", "qute://*/*", @@ -74,7 +75,7 @@ config.source('colorscheme.py') # should be visible to prevent 'jumping' bug, # see https://github.com/qutebrowser/qutebrowser/issues/2236 # TODO think about implementing a simple toggle for the statusbar -c.statusbar.show = "in-mode" +c.statusbar.show = "always" c.colors.webpage.bg = "#555555" @@ -89,7 +90,7 @@ c.session.lazy_restore = True leader = "" # toggles ('cycles') between tabs always showing, or only when switching between them -config.bind(leader + "tt", "config-cycle -t tabs.show switching always") +config.bind(leader + "tt", "config-cycle -t tabs.show always switching;; config-cycle -t statusbar.show always in-mode") config.bind(leader + "th", "set tabs.position bottom") config.bind(leader + "tH", "set tabs.position top") config.bind(leader + "tv", "set tabs.position right") @@ -125,6 +126,11 @@ config.bind(leader + "bs", "add-shaarli", mode="normal") # re-opens the current page on the web archive overview page c.aliases["archive-open"] = "open https://web.archive.org/web/{url}" config.bind(leader + "ba", "archive-open", mode="normal") +# translate current page / selection with google translate +c.aliases["translate-page"] = "spawn --userscript translate_google.sh" +c.aliases["translate-selection"] = "spawn --userscript translate_google.sh --text" +config.bind(leader + "bg", "translate-page", mode="normal") +config.bind(leader + "bG", "translate-selection", mode="normal") # save current page to pdf file c.aliases["printpdf"] = "spawn --userscript pagetopdf.sh" @@ -149,6 +155,7 @@ config.bind(leader + "VV", "config-source") c.url.searchengines = { "DEFAULT": "https://search.martyoeh.me/?q={}", + "l": "https://links.martyoeh.me/?searchterm={}&searchtags=", "ddg": "https://duckduckgo.com/?q={}", "d": "https://www.dict.cc/?s={}", "t": "https://www.thesaurus.com/browse/{}", @@ -164,5 +171,7 @@ c.url.searchengines = { "maps": "https://www.google.fr/maps?q={}", "gol": "https://golang.org/pkg/{}/", "man": "https://manned.org/browse/search?q={}", - "alt": "https://alternativeto.net/software/{}", + "lib": "http://libgen.rs/search.php?req={}", + "kb": "https://soeg.kb.dk/discovery/search?query=any,contains,{}&tab=Everything&search_scope=MyInst_and_CI&vid=45KBDK_KGL:KGL&offset=0&lang=en", + "alt": "https://alternativeto.net/software/{}/?license=opensource", } diff --git a/qutebrowser/.config/qutebrowser/quickmarks b/qutebrowser/.config/qutebrowser/quickmarks index 0df2249..d368c4c 100644 --- a/qutebrowser/.config/qutebrowser/quickmarks +++ b/qutebrowser/.config/qutebrowser/quickmarks @@ -1,11 +1,16 @@ -dot https://gitlab.com/marty-oehme/dotfiles -l https://links.martyoeh.me/ -todo https://todoist.com/app?lang=de#start -mail https://mail.google.com/mail/u/0/h/1bka5wod4ul0p/?zy=e&f=1 -rss https://rss.martyoeh.me/ -files http://files.martyoeh.me/ -read https://read.martyoeh.me/ arch https://wiki.archlinux.org/ -toggl https://toggl.com/app/timer clock http://clockify.me/tracker -cal https://calendar.google.com/calendar/r +dot https://gitlab.com/marty-oehme/dotfiles +nomie https://v5.nomie.app/ +todo https://todoist.com/app?lang=de#start +toggl https://toggl.com/app/timer +# personal +blog https://blog.martyoeh.me/ +cal https://files.martyoeh.me/apps/calendar/timeGridWeek/2020-10-28 +emgs https://emgs.martyoeh.me/ +files http://files.martyoeh.me/ +l https://links.martyoeh.me/ +mail https://files.martyoeh.me/apps/mail/box/priority +photos https://files.martyoeh.me/apps/photos/ +read https://read.martyoeh.me/ +rss https://rss.martyoeh.me/ diff --git a/qutebrowser/.config/qutebrowser/stylesheets/stylesheet.css b/qutebrowser/.config/qutebrowser/stylesheets/stylesheet.css deleted file mode 100644 index e69de29..0000000 diff --git a/qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh b/qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh new file mode 100755 index 0000000..23de0af --- /dev/null +++ b/qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh @@ -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"