Last active
August 11, 2024 16:09
-
-
Save Gavinok/f9c310a66576dc00329dd7bef2b122a1 to your computer and use it in GitHub Desktop.
This is a simplified version of my qutebrowser config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import os | |
from qutebrowser.api import interceptor | |
""" | |
qutebrowser settings for video | |
for more settings check out | |
https://qutebrowser.org/doc/help/settings.html | |
""" | |
# ================== Youtube Add Blocking ======================= {{{ | |
def filter_yt(info: interceptor.Request): | |
"""Block the given request if necessary.""" | |
url = info.request_url | |
if ( | |
url.host() == "www.youtube.com" | |
and url.path() == "/get_video_info" | |
and "&adformat=" in url.query() | |
): | |
info.block() | |
interceptor.register(filter_yt) | |
# }}} | |
# =================== Launch Qutebrowser from Dmenu ====== {{{ | |
""" | |
#!/bin/sh | |
# Originally from lukesmith with some changes | |
# Gives a dmenu prompt to search DuckDuckGo. | |
# Without input, will open DuckDuckGo.com. | |
# Anything else, it search it. | |
LAUNCER="dmenu -l 5 -i -p " | |
[ -z "${DISPLAY}" ] && LAUNCER="fzf --prompt " | |
localBROWSER="$BROWSER " | |
[ -n "$*" ] && localBROWSER="$*" | |
[ -z "${DISPLAY}" ] && localBROWSER="w3m " | |
if [ -f ~/.config/bookmarks ]; then | |
choice=$( (echo "🦆" && cat ~/.config/bookmarks) | $LAUNCER"Search:") || exit 1 | |
else | |
choice=$(echo "🦆" | $LAUNCER -i -p "Search DuckDuckGo:") || exit 1 | |
fi | |
case "$choice" in | |
*🦆*) | |
$localBROWSER"https://duckduckgo.com" | |
exit | |
;; | |
http*) | |
$localBROWSER"$(echo $choice | awk '{print $1}')" | |
exit | |
;; | |
*) $localBROWSER"https://duckduckgo.com/?q=$choice" | |
exit | |
;; | |
esac | |
#vim:ft=sh | |
""" | |
# }}} | |
# ====================== Special Format Yanking =========== {{{ | |
config.bind("<y><o>", "yank inline [[{url}][{title}]]") | |
# }}} | |
# ====================== Open Notes From Qutebrowser ====== {{{ | |
notecmd = "yank inline [[{url}][{title}]];; spawn " +\ | |
os.environ["TERMINAL"] + " -e " + os.environ["EDITOR"] + \ | |
" -c 'call CreateCapture(\"e\" , \"qutebrowser\")'" | |
config.bind("gn", notecmd) | |
""" | |
" PART OF MY VIMRC | |
" I used minisnip to execute the vimscript but you could just use autocommands | |
" Simple implementation of org-capture using minisnip | |
function! CreateCapture(window, ...) | |
" file used to store all captures | |
let g:org_refile='~/Documents/org/refile.org' | |
if a:0 == 1 && a:1 == 'qutebrowser' | |
exec a:window . ' ' . g:org_refile | |
exec '$read ' . globpath(&rtp, 'extra/org/templateQUTE.org') | |
endif | |
call feedkeys("i\\<Plug>(minisnip)", 'i') | |
endfunction | |
""" | |
""" | |
" ~/.vim/extra/org/templateQUTE.org | |
* TODO {{+~getreg('+')+}} | |
SCHEDULED: <{{+~strftime(g:org_date_format)+}}> | |
""" | |
# }}} | |
# ======================= External Open =================== {{{ | |
config.bind("V", "hint links spawn " + os.environ["BROWSER"] + ' "{hint-url}"') | |
config.bind("v", 'hint links spawn funnel "{hint-url}"') | |
config.bind("\\", 'spawn dmenuhandler "{url}"') | |
# }}} | |
# ======================= Redline Insert Mode ============= {{{ | |
# Awesome way to open vim from qutebrowser | |
c.editor.command = [ | |
os.environ["TERMINAL"], | |
"-e", | |
os.environ["EDITOR"], | |
"-f", | |
"{file}", | |
"-c", | |
"normal {line}G{column0}1", | |
] | |
config.bind("<Ctrl-h>", "fake-key <Backspace>", "insert") | |
config.bind("<Ctrl-a>", "fake-key <Home>", "insert") | |
config.bind("<Ctrl-e>", "fake-key <End>", "insert") | |
config.bind("<Ctrl-b>", "fake-key <Left>", "insert") | |
config.bind("<Mod1-b>", "fake-key <Ctrl-Left>", "insert") | |
config.bind("<Ctrl-f>", "fake-key <Right>", "insert") | |
config.bind("<Mod1-f>", "fake-key <Ctrl-Right>", "insert") | |
config.bind("<Ctrl-p>", "fake-key <Up>", "insert") | |
config.bind("<Ctrl-n>", "fake-key <Down>", "insert") | |
config.bind("<Mod1-d>", "fake-key <Ctrl-Delete>", "insert") | |
config.bind("<Ctrl-d>", "fake-key <Delete>", "insert") | |
config.bind("<Ctrl-w>", "fake-key <Ctrl-Backspace>", "insert") | |
config.bind("<Ctrl-u>", "fake-key <Shift-Home><Delete>", "insert") | |
config.bind("<Ctrl-k>", "fake-key <Shift-End><Delete>", "insert") | |
config.bind("<Ctrl-x><Ctrl-e>", "open-editor", "insert") | |
# }}} | |
# ====================== xresources ======================= {{{ | |
# taken from https://qutebrowser.org/doc/help/configuring.html | |
def read_xresources(prefix): | |
""" | |
read settings from xresources | |
""" | |
props = {} | |
x = subprocess.run(["xrdb", "-query"], stdout=subprocess.PIPE) | |
lines = x.stdout.decode().split("\n") | |
for line in filter(lambda l: l.startswith(prefix), lines): | |
prop, _, value = line.partition(":\t") | |
props[prop] = value | |
return props | |
xresources = read_xresources("*") | |
c.colors.statusbar.normal.bg = xresources["*.background"] | |
c.colors.statusbar.command.bg = xresources["*.background"] | |
c.colors.statusbar.command.fg = xresources["*.foreground"] | |
c.colors.statusbar.normal.fg = xresources["*.foreground"] | |
c.statusbar.show = "always" | |
c.colors.tabs.even.bg = xresources["*.background"] | |
c.colors.tabs.odd.bg = xresources["*.background"] | |
c.colors.tabs.even.fg = xresources["*.foreground"] | |
c.colors.tabs.odd.fg = xresources["*.foreground"] | |
c.colors.tabs.selected.even.bg = xresources["*.color8"] | |
c.colors.tabs.selected.odd.bg = xresources["*.color8"] | |
c.colors.hints.bg = xresources["*.background"] | |
c.colors.hints.fg = xresources["*.foreground"] | |
c.tabs.show = "multiple" | |
# change title format | |
c.tabs.title.format = "{audio}{current_title}" | |
# fonts | |
c.fonts.web.size.default = 20 | |
c.colors.tabs.indicator.stop = xresources["*.color14"] | |
c.colors.completion.odd.bg = xresources["*.background"] | |
c.colors.completion.even.bg = xresources["*.background"] | |
c.colors.completion.fg = xresources["*.foreground"] | |
c.colors.completion.category.bg = xresources["*.background"] | |
c.colors.completion.category.fg = xresources["*.foreground"] | |
c.colors.completion.item.selected.bg = xresources["*.background"] | |
c.colors.completion.item.selected.fg = xresources["*.foreground"] | |
# If not in light theme | |
if xresources["*.background"] != "#ffffff": | |
# c.qt.args = ['blink-settings=darkMode=4'] | |
# c.colors.webpage.prefers_color_scheme_dark = True | |
c.colors.webpage.darkmode.enabled = True | |
c.hints.border = "1px solid #FFFFFF" | |
# USERSCRIPTS | |
# | |
# personally I use | |
# - for password managment | |
# - qute-pass | |
# - for chrome casting I use | |
# - cast | |
# - I have been looking at using catt instead of castnow | |
# }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@zKBTuran Network based YouTube adblocks don't work any more because YouTube loads ads dynamically. The closest you can get is ads skipper available in this bug report comment.