split qutebrowser.py

This commit is contained in:
lelgenio 2020-11-28 00:23:33 -03:00
parent e78a3fb325
commit 8fdb383f8e
9 changed files with 451 additions and 339 deletions

View File

@ -183,8 +183,8 @@ dotfiles: # {{{
actions:
- reload_fish
qutebrowser:
src: qutebrowser.py
dst: ~/.config/qutebrowser/config.py
src: qutebrowser
dst: ~/.config/qutebrowser
lesskey:
src: lesskey
dst: ~/.lesskey

View File

@ -1,337 +0,0 @@
#!/bin/env python
# {{@@ header() @@}}
# Ignore import error
# pylint: disable=E0401,E0602
# type: ignore
from qutebrowser.config.configfiles import ConfigAPI
from qutebrowser.config.config import ConfigContainer
config = config
c = c
# Ignore undefined
config: ConfigAPI
c: ConfigContainer
# Behavior {{{
c.aliases = {
"q": "close",
"qa": "quit",
"w": "session-save",
"wq": "quit --save",
"wqa": "quit --save",
}
# Load a restored tab as soon as it takes focus.
c.session.lazy_restore = True
# Enable screensharing for wayland
c.qt.args = ['enable-features=WebRTCPipeWireCapturer']
# Always restore open sites when qutebrowser is reopened.
c.auto_save.session = True
config.set("content.cookies.accept", "all", "chrome-devtools://*")
config.set("content.cookies.accept", "all", "devtools://*")
# Allow websites to request geolocations.
config.set("content.geolocation", True, "https://openweathermap.org")
c.content.headers.user_agent = """\
Mozilla/5.0 ({os_info})
AppleWebKit/{webkit_version} (KHTML, like Gecko)
{qt_key}/{qt_version}
{upstream_browser_key}/{upstream_browser_version}
Safari/{webkit_version}""".replace("\n", "")
# Enable JavaScript.
config.set("content.javascript.enabled", True, "file://*")
config.set("content.javascript.enabled", True, "chrome-devtools://*")
config.set("content.javascript.enabled", True, "devtools://*")
config.set("content.javascript.enabled", True, "chrome://*/*")
config.set("content.javascript.enabled", True, "qute://*/*")
# Allow websites to record audio/video.
# config.set("content.media_capture", True, "https://ca.bbcollab.com")
config.set("content.media.audio_video_capture", True,
"https://ca.bbcollab.com")
config.set("content.autoplay", True, "https://ca.bbcollab.com")
config.set("content.mute", False, "https://ca.bbcollab.com")
# Allow websites to show notifications.
config.set("content.notifications", False, "*")
# Allow websites to register protocol handlers via
config.set('content.register_protocol_handler', False,
'https://mail.disroot.org?mailto&to=%25s')
c.content.mute = True
c.content.autoplay = False
editor = "{{@@ editor @@}}"
c.editor.command = ["terminal", editor, "{file}", "+{line}"]
# }}}
# UI {{{
# Shrink the completion to be smaller than the configured size if there
# are no scrollbars.
# Type: Bool
c.completion.shrink = True
# CSS border value for hints.
# Type: String
c.hints.border = "2px solid {{@@ accent_color @@}}"
# Characters used for hint strings.
# {%@@ if key_layout == "colemak" @@%} #
c.hints.chars = "asrtdhneio"
# {%@@ elif key_layout == "dvorak" @@%} #
c.hints.chars = "aoeuidnths"
# {%@@ endif @@%}
# c.input.insert_mode.auto_leave = False
# Scrollbar style
c.scrolling.bar = 'overlay'
c.scrolling.smooth = True
c.statusbar.widgets = ["keypress", "url", "scroll", "history", "tabs"]
c.tabs.favicons.show = "always"
c.tabs.select_on_remove = "last-used"
# When to show the status/tab bar.
c.tabs.show = "always"
c.statusbar.show = "always"
c.tabs.show_switching_delay = 2000
c.tabs.title.format = "{audio} {current_title}"
c.tabs.indicator.width = 0
# }}}
# Search {{{
# {%@@ set search_engine = "start.duckduckgo.com" @@%} #
c.url.default_page = "{{@@ search_engine @@}}"
c.url.searchengines = {
"DEFAULT": "{{@@ search_engine @@}}?q={}",
"!aw": "wiki.archlinux.org?search={}",
"!w": "wikipedia.org/w?search={}",
"!wpt": "pt.wikipedia.org/w?search={}",
"!au": "aur.archlinux.org/packages/?K={}",
"!alt": "alternativeto.net/browse/search?q={}",
"!gw": "wiki.gentoo.org/?search={}",
"!yt": "youtube.com/results?q={}",
}
# Page(s) to open at the start.
# Type: List of FuzzyUrl, or FuzzyUrl
c.url.start_pages = "{{@@ search_engine @@}}"
# }}}
# Colors {{{
class color:
accent = "{{@@ accent_color @@}}"
txt = "{{@@ color.txt @@}}"
bg = "{{@@ color.bg @@}}"
bg_dark = "{{@@ color.bg_dark @@}}"
bg_light = "{{@@ color.bg_light @@}}"
c.colors.completion.category.fg = color.txt
c.colors.completion.category.bg = color.bg_light
c.colors.completion.category.border.top = color.bg_dark
c.colors.completion.category.border.bottom = color.bg_dark
c.colors.completion.item.selected.fg = color.txt
c.colors.completion.item.selected.bg = color.accent
c.colors.completion.item.selected.border.top = color.bg_dark
c.colors.completion.item.selected.border.bottom = color.bg_dark
c.colors.completion.fg = color.txt
c.colors.completion.even.bg = color.bg
c.colors.completion.odd.bg = color.bg
c.colors.completion.item.selected.match.fg = color.txt
c.colors.completion.scrollbar.bg = color.bg_light
c.colors.downloads.bar.bg = color.bg
c.colors.downloads.start.bg = "{{@@ color.normal.blue @@}}"
c.colors.downloads.stop.bg = "{{@@ color.normal.green @@}}"
c.colors.hints.fg = color.txt
c.colors.hints.bg = color.bg
c.colors.hints.match.fg = color.accent
c.colors.keyhint.suffix.fg = color.accent
c.colors.keyhint.fg = color.txt
c.colors.keyhint.bg = "rgba({{@@ hex2rgb(color.bg) @@}}, {{@@ opacity @@}})"
c.colors.statusbar.normal.fg = color.txt
c.colors.statusbar.normal.bg = color.bg
c.colors.statusbar.insert.bg = color.bg
c.colors.statusbar.command.fg = color.txt
c.colors.statusbar.command.bg = color.bg
c.colors.statusbar.caret.selection.bg = color.accent
c.colors.statusbar.url.success.https.fg = color.txt
c.colors.statusbar.url.success.http.fg = "{{@@ color.normal.yellow @@}}"
c.colors.statusbar.url.hover.fg = "{{@@ color.normal.cyan @@}}"
c.colors.statusbar.insert.fg = "{{@@ color.normal.green @@}}"
c.colors.tabs.bar.bg = color.bg
c.colors.tabs.even.fg = color.txt
c.colors.tabs.odd.fg = color.txt
c.colors.tabs.even.bg = color.bg
c.colors.tabs.odd.bg = color.bg
c.colors.tabs.selected.even.fg = color.txt
c.colors.tabs.selected.odd.fg = color.txt
c.colors.tabs.selected.even.bg = color.accent
c.colors.tabs.selected.odd.bg = color.accent
c.colors.tabs.pinned.selected.odd.bg = color.accent
c.colors.tabs.pinned.selected.even.bg = color.accent
c.colors.contextmenu.menu.bg = color.bg
c.colors.contextmenu.menu.fg = color.txt
c.colors.contextmenu.selected.bg = color.accent
c.colors.contextmenu.disabled.fg = color.bg_light
# {%@@ if color.type == "dark" @@%} #
c.colors.webpage.bg = color.bg
c.colors.webpage.prefers_color_scheme_dark = True
c.colors.webpage.darkmode.enabled = True
c.colors.webpage.darkmode.threshold.background = 256 // 2
c.colors.webpage.darkmode.threshold.text = 256 // 2
# {%@@ endif @@%}
# }}}
# Fonts {{{
class fonts:
DEF_MONO = "{{@@ font.size.medium @@}}px {{@@ font.mono @@}}"
BIG_MONO = "{{@@ font.size.big @@}}px {{@@ font.mono @@}}"
DEF_INTER = "{{@@ font.size.medium @@}}px {{@@ font.interface @@}}"
BIG_INTER = "{{@@ font.size.big @@}}px {{@@ font.interface @@}}"
c.fonts.completion.entry = fonts.BIG_INTER
c.fonts.completion.category = fonts.BIG_INTER
c.fonts.debug_console = fonts.BIG_INTER
c.fonts.hints = 'bold ' + fonts.BIG_MONO
c.fonts.keyhint = fonts.BIG_INTER
c.fonts.messages.error = fonts.BIG_INTER
c.fonts.messages.info = fonts.BIG_INTER
c.fonts.messages.warning = fonts.BIG_INTER
c.fonts.statusbar = fonts.DEF_MONO
c.fonts.tabs.selected = fonts.DEF_INTER
c.fonts.tabs.unselected = fonts.DEF_INTER
c.fonts.prompts = fonts.BIG_INTER
c.fonts.downloads = fonts.BIG_INTER
# }}}
# Bindings {{{
# Bindings for normal mode
class key:
up = "{{@@ key.up @@}}"
down = "{{@@ key.down @@}}"
left = "{{@@ key.left @@}}"
right = "{{@@ key.right @@}}"
tabL = "{{@@ key.tabL @@}}"
tabR = "{{@@ key.tabR @@}}"
insert = "{{@@ key.insertMode @@}}"
next = "{{@@ key.next @@}}"
def edbind(k, v):
if editor == "kak":
config.bind("<Alt-{}>".format(k), v)
config.bind(k.upper(), "nop")
else:
config.bind(k.upper(), v)
config.bind(",d", "spawn --verbose youtube-dl -fbest[ext=mp4] {url}")
config.bind(",m", "spawn --userscript view_in_mpv")
config.bind(",r", "spawn --userscript readability")
config.bind(";e", "hint links spawn deemix '{hint-url}'")
config.bind(";m", "hint links spawn mpv --fs {hint-url}")
# {%@@ if key_layout == "colemak" @@%} #
config.bind("t", "hint all")
config.bind("h", "set-cmd-text -s :open")
for k, v in {
"T": "hint all tab",
"H": "set-cmd-text -s :open -t",
}.items():
edbind(k, v)
# {%@@ endif @@%}
config.bind(key.insert, "enter-mode insert")
config.bind(key.next, "search-next")
config.bind(key.next.upper(), "search-prev")
config.bind(key.left, "scroll left")
config.bind(key.down, "scroll down")
config.bind(key.up, "scroll up")
config.bind(key.right, "scroll right")
for k, v in {
key.up: "scroll-px 0 -100",
key.down: "scroll-px 0 100",
key.left: "back",
key.right: "forward",
key.tabL: "tab-prev",
key.tabR: "tab-next",
}.items():
edbind(k, v)
# Bindings for caret mode
config.bind(key.left, "move-to-prev-char", mode="caret")
config.bind(key.up, "move-to-prev-line", mode="caret")
config.bind(key.down, "move-to-next-line", mode="caret")
config.bind(key.right, "move-to-next-char", mode="caret")
# devtools
config.unbind("wIh")
config.unbind("wIj")
config.unbind("wIk")
config.unbind("wIl")
config.bind("wIf", "devtools-focus")
config.bind("wIw", "devtools window")
config.bind("wI" + key.left, "devtools left")
config.bind("wI" + key.down, "devtools bottom")
config.bind("wI" + key.up, "devtools top")
config.bind("wI" + key.right, "devtools right")
# }}}
# vim: fdm=marker

View File

@ -0,0 +1,126 @@
colors:
########################################################
# Tabs
########################################################
tabs:
bar:
bg: "{{@@ color.bg @@}}"
odd:
bg: "{{@@ color.bg @@}}"
fg: "{{@@ color.txt @@}}"
even:
bg: "{{@@ color.bg_dark @@}}"
fg: "{{@@ color.txt @@}}"
selected:
odd:
bg: "{{@@ accent_color @@}}"
fg: "{{@@ color.txt @@}}"
even:
bg: "{{@@ accent_color @@}}"
fg: "{{@@ color.txt @@}}"
pinned:
selected:
odd:
bg: "{{@@ color.bg @@}}"
even:
bg: "{{@@ color.bg_dark @@}}"
########################################################
# Completion for urls and commands
########################################################
completion:
fg: "{{@@ color.txt @@}}"
even:
bg: "{{@@ color.bg @@}}"
odd:
bg: "{{@@ color.bg @@}}"
scrollbar:
bg: "{{@@ color.bg_light @@}}"
category:
fg: "{{@@ color.txt @@}}"
bg: "{{@@ color.bg_light @@}}"
border:
top: "{{@@ color.bg_dark @@}}"
bottom: "{{@@ color.bg_dark @@}}"
item:
selected:
fg: "{{@@ color.txt @@}}"
bg: "{{@@ accent_color @@}}"
border:
top: "{{@@ color.bg_dark @@}}"
bottom: "{{@@ color.bg_dark @@}}"
match:
fg: "{{@@ color.txt @@}}"
########################################################
# Statusbar
########################################################
statusbar:
normal:
fg: "{{@@ color.txt @@}}"
bg: "{{@@ color.bg @@}}"
insert:
fg: "{{@@ color.normal.green @@}}"
bg: "{{@@ color.bg @@}}"
command:
fg: "{{@@ color.txt @@}}"
bg: "{{@@ color.bg @@}}"
caret:
selection:
bg: "{{@@ accent_color @@}}"
url:
success:
https:
fg: "{{@@ color.txt @@}}"
fg: "{{@@ color.normal.yellow @@}}"
hover:
fg: "{{@@ color.normal.cyan @@}}"
########################################################
# Downloads
########################################################
downloads:
start:
bg: "{{@@ color.normal.blue @@}}"
stop:
bg: "{{@@ color.normal.green @@}}"
bar:
bg: "{{@@ color.bg @@}}"
########################################################
# Choice of what element should be clicked
########################################################
hints:
fg: "{{@@ color.txt @@}}"
bg: "{{@@ color.bg @@}}"
match:
fg: "{{@@ accent_color @@}}"
########################################################
# List of what each keybinding does
########################################################
keyhint:
fg: "{{@@ color.txt @@}}"
bg: "rgba({{@@ hex2rgb(color.bg) @@}}, {{@@ opacity @@}})"
suffix:
fg: "{{@@ accent_color @@}}"
########################################################
# Right click menu
########################################################
contextmenu:
menu:
bg: "{{@@ color.bg @@}}"
fg: "{{@@ color.txt @@}}"
selected:
bg: "{{@@ accent_color @@}}"
disabled:
fg: "{{@@ color.bg_light @@}}"
########################################################
# Dark theme
########################################################
# {%@@ if color.type == "dark" @@%} #
webpage:
bg: "{{@@ color.bg @@}}"
prefers_color_scheme_dark: True
darkmode:
enabled: True
threshold:
background: {{@@ 256 // 2 @@}}
text: {{@@ 256 // 2 @@}}
# {%@@ endif @@%}

View File

@ -0,0 +1,53 @@
#!/bin/env python
# {{@@ header() @@}}
from source_yaml import source_yaml
from qutebrowser.config.configfiles import ConfigAPI # type: ignore
from qutebrowser.config.config import ConfigContainer # type: ignore
# {%@@ if False @@%}
config = ConfigAPI()
c = ConfigContainer()
# {%@@ endif @@%}
########################################################################
# Imports
########################################################################
source_yaml(config, "colors.yaml")
source_yaml(config, "fonts.yaml")
config.source("keys.py")
config.source("ui.py")
config.source("permissons.py")
########################################################################
# General options
########################################################################
# Load a restored tab as soon as it takes focus.
c.session.lazy_restore = True
# Always restore open sites when qutebrowser is reopened.
c.auto_save.session = True
# what command to run on [InsertMode]ctrl+e (default)
c.editor.command = ["terminal", "{{@@ editor @@}}", "{file}", "+{line}"]
########################################################################
# Search
########################################################################
search_engine = "start.duckduckgo.com"
c.url.default_page = search_engine
c.url.start_pages = search_engine
c.url.searchengines = {
"DEFAULT": search_engine + "?q={}",
"!aw": "wiki.archlinux.org?search={}",
"!w": "wikipedia.org/w?search={}",
"!wpt": "pt.wikipedia.org/w?search={}",
"!au": "aur.archlinux.org/packages/?K={}",
"!alt": "alternativeto.net/browse/search?q={}",
"!gw": "wiki.gentoo.org/?search={}",
"!yt": "youtube.com/results?q={}",
}

View File

@ -0,0 +1,24 @@
{%@@ set DEF_MONO = "{}px {}".format(font.size.medium, font.mono) @@%}
{%@@ set BIG_MONO = "{}px {}".format(font.size.big, font.mono) @@%}
{%@@ set DEF_INTER = "{}px {}".format(font.size.medium, font.interface) @@%}
{%@@ set BIG_INTER = "{}px {}".format(font.size.big, font.interface) @@%}
fonts:
debug_console: "{{@@ BIG_INTER @@}}"
downloads: "{{@@ BIG_INTER @@}}"
hints: "{{@@ 'bold ' + BIG_MONO @@}}"
keyhint: "{{@@ BIG_INTER @@}}"
prompts: "{{@@ BIG_INTER @@}}"
statusbar: "{{@@ DEF_MONO @@}}"
completion:
entry: "{{@@ BIG_INTER @@}}"
category: "{{@@ BIG_INTER @@}}"
messages:
error: "{{@@ BIG_INTER @@}}"
info: "{{@@ BIG_INTER @@}}"
warning: "{{@@ BIG_INTER @@}}"
tabs:
selected: "{{@@ DEF_INTER @@}}"
unselected: "{{@@ DEF_INTER @@}}"

View File

@ -0,0 +1,118 @@
from qutebrowser.config.configfiles import ConfigAPI # type: ignore
from qutebrowser.config.config import ConfigContainer # type: ignore
# {%@@ if False @@%}
config = ConfigAPI()
c = ConfigContainer()
# {%@@ endif @@%}
##########################################################
# Helpers
##########################################################
class key:
"Object mapping of templated key bindings"
up = "{{@@ key.up @@}}"
down = "{{@@ key.down @@}}"
left = "{{@@ key.left @@}}"
right = "{{@@ key.right @@}}"
tabL = "{{@@ key.tabL @@}}"
tabR = "{{@@ key.tabR @@}}"
insert = "{{@@ key.insertMode @@}}"
next = "{{@@ key.next @@}}"
def edbind(k, v):
if "{{@@ editor @@}}" == "kak":
config.bind("<Alt-{}>".format(k), v)
config.bind(k.upper(), "nop")
else:
config.bind(k.upper(), v)
##########################################################
# Usermode
##########################################################
config.bind(",d", "spawn --verbose youtube-dl -fbest[ext=mp4] {url}")
config.bind(",m", "spawn --userscript view_in_mpv")
config.bind(",r", "spawn --userscript readability")
config.bind(";e", "hint links spawn deemix '{hint-url}'")
config.bind(";m", "hint links spawn mpv --fs {hint-url}")
##########################################################
# Layout specific
##########################################################
key_layout = "{{@@ key_layout @@}}"
if key_layout == "colemak":
config.bind("t", "hint all")
config.bind("h", "set-cmd-text -s :open")
edbind("T", "hint all tab")
edbind("H", "set-cmd-text -s :open -t")
c.hints.chars = "asrtdhneio"
elif key_layout == "dvorak":
c.hints.chars = "aoeuidnths"
##########################################################
# Movement
##########################################################
config.bind(key.left, "scroll left")
config.bind(key.down, "scroll down")
config.bind(key.up, "scroll up")
config.bind(key.right, "scroll right")
config.bind(key.next, "search-next")
config.bind(key.next.upper(), "search-prev")
for k, v in {
key.up: "scroll-px 0 -100",
key.down: "scroll-px 0 100",
key.left: "back",
key.right: "forward",
key.tabL: "tab-prev",
key.tabR: "tab-next",
}.items():
edbind(k, v)
##########################################################
# Insert mode
##########################################################
config.bind(key.insert, "enter-mode insert")
c.input.insert_mode.auto_leave = False
##########################################################
# Caret mode
##########################################################
config.bind(key.left, "move-to-prev-char", mode="caret")
config.bind(key.up, "move-to-prev-line", mode="caret")
config.bind(key.down, "move-to-next-line", mode="caret")
config.bind(key.right, "move-to-next-char", mode="caret")
##########################################################
# devtools
##########################################################
# Clear old binds
config.unbind("wIh")
config.unbind("wIj")
config.unbind("wIk")
config.unbind("wIl")
config.bind("wIf", "devtools-focus")
config.bind("wIw", "devtools window")
config.bind("wI" + key.left, "devtools left")
config.bind("wI" + key.down, "devtools bottom")
config.bind("wI" + key.up, "devtools top")
config.bind("wI" + key.right, "devtools right")

View File

@ -0,0 +1,60 @@
#!/bin/env python
# {{@@ header() @@}}
from qutebrowser.config.configfiles import ConfigAPI # type: ignore
from qutebrowser.config.config import ConfigContainer # type: ignore
# {%@@ if False @@%}
config = ConfigAPI()
c = ConfigContainer()
# {%@@ endif @@%}
###############################################################
# Global
###############################################################
c.content.mute = True
c.content.autoplay = False
c.content.headers.user_agent = """\
Mozilla/5.0 ({os_info})
AppleWebKit/{webkit_version} (KHTML, like Gecko)
{qt_key}/{qt_version}
{upstream_browser_key}/{upstream_browser_version}
Safari/{webkit_version}""".replace("\n", "")
# STFU
config.set("content.notifications", False, "*")
config.set('content.register_protocol_handler', False, '*')
###############################################################
# Single website settings
###############################################################
# Allow websites to request geolocations.
config.set("content.geolocation", True, "https://openweathermap.org")
# Allow websites to record audio/video.
# config.set("content.media_capture", True, "https://ca.bbcollab.com")
config.set("content.media.audio_video_capture", True,
"https://ca.bbcollab.com")
config.set("content.autoplay", True, "https://ca.bbcollab.com")
config.set("content.mute", False, "https://ca.bbcollab.com")
###############################################################
# Internals
###############################################################
# Enable JavaScript.
config.set("content.javascript.enabled", True, "file://*")
config.set("content.javascript.enabled", True, "chrome-devtools://*")
config.set("content.javascript.enabled", True, "devtools://*")
config.set("content.javascript.enabled", True, "chrome://*/*")
config.set("content.javascript.enabled", True, "qute://*/*")
config.set("content.cookies.accept", "all", "chrome-devtools://*")
config.set("content.cookies.accept", "all", "devtools://*")

View File

@ -0,0 +1,23 @@
#!/bin/env python
# {{@@ header() @@}}
import yaml
from qutebrowser.config.configfiles import ConfigAPI # type: ignore
def dict_attrs(obj, path=''):
if isinstance(obj, dict):
for k, v in obj.items():
yield from dict_attrs(v, '{}.{}'.format(path, k) if path else k)
else:
yield path, obj
def source_yaml(config: ConfigAPI, filename: str):
with (config.configdir / filename).open() as f:
yaml_data = yaml.safe_load(f)
for k, v in dict_attrs(yaml_data):
config.set(k, v)

View File

@ -0,0 +1,45 @@
#!/bin/env python
# {{@@ header() @@}}
from qutebrowser.config.configfiles import ConfigAPI # type: ignore
from qutebrowser.config.config import ConfigContainer # type: ignore
# {%@@ if False @@%}
config = ConfigAPI()
c = ConfigContainer()
# {%@@ endif @@%}
#################################################
# Hints
#################################################
c.hints.border = "2px solid {{@@ accent_color @@}}"
#################################################
# Scrolling
#################################################
c.scrolling.bar = 'overlay'
c.scrolling.smooth = True
#################################################
# Tabs
#################################################
c.tabs.show = "multiple"
c.tabs.favicons.show = "always"
c.tabs.title.format = "{audio} {current_title}"
c.tabs.indicator.width = 0
c.tabs.select_on_remove = "last-used"
c.tabs.show_switching_delay = 2000
#################################################
# Statusbar
#################################################
c.statusbar.show = "always"
c.completion.shrink = True
c.statusbar.widgets = ["keypress", "url", "scroll", "history", "tabs"]