Files
dotfiles/common/qutebrowser/userscripts/rebuild-qutebrowser-grease-styles.py
T
connor e6644d0616 Rebuild dotfiles as one branch with per-host layers
Replaces the previous repo, which had split into two histories that never
met (mainframe on a dead GitLab remote, the laptops on Gitea) with 146
dirty files across three machines and the NAS never enrolled at all.

Branch-per-machine is gone. One main, with host differences expressed as
small files under hosts/<hostname>/ rather than as branches, so there is
nothing to merge. The reconciled zsh layer reduces 15-33 line forks to
1-7 effective lines per host; distro differences (oh-my-zsh prefix,
syntax-highlighting path, fd vs fdfind) are probed in common/ instead.

Fresh history: the old one carried six plaintext credentials, 45 MB of
mail caches, browser caches and vendored binaries. 5,096 tracked files
and 144 MB become 462 files and 2.6 MB. The .gitignore is now an
allowlist, which is what keeps that true.

Root cause of the rot: ~/.local/bin was a symlink to scripts/ with GOPATH
inside it, so every go install wrote into version control (2.2 GB on the
work laptop). PATH now points at the repo instead of the reverse.

Also: Hyprland replaces sway and is sourced in two halves so $browser is
defined before use; singleton automations carry ConditionHost= alongside
host-layer-only placement; ddns moves from cron to a guarded timer;
package manifests and pkg-snapshot/pkg-restore replace the X11-era
install_scripts/; networkmanager-dmenu added to system76 (the binding
always existed, the package never did).
2026-09-14 14:24:37 -04:00

70 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python
import os
import importlib.machinery as im
import importlib.util as iu
class RebuildGreaseStyles(object):
def __init__(self):
self.config_dir = self.get_config_dir()
self.stylemap = self.import_stylemap(self.config_dir)
def get_config_dir(self):
config_dir = os.getenv('QUTE_CONFIG_DIR')
if config_dir: return config_dir
dir = os.getenv('XDG_CONFIG_HOME')
if dir: return dir + '/qutebrowser'
dir = os.getenv('HOME', '~')
return dir + '/.config/qutebrowser'
def import_stylemap(self, config_dir):
loader = im.SourceFileLoader('stylemap', f"{config_dir}/stylemap.py")
spec = iu.spec_from_loader( 'stylemap', loader )
if spec:
stylemap = iu.module_from_spec( spec )
loader.exec_module( stylemap )
return stylemap.styles
def create_grease_scripts_from_css_files(self):
if not self.stylemap: return
for css_filename, patterns in self.stylemap.items():
self.create_grease_script_from_css_file(css_filename, patterns)
def create_grease_script_from_css_file(self, css_filename, patterns):
with open(f'{self.config_dir}/styles/{css_filename}') as css_file:
css = css_file.read()
grease = self.css_to_grease(css_filename, css, patterns)
grease_script_path = f'{self.config_dir}/greasemonkey/{css_filename}.js'
with open(grease_script_path, 'w') as grease_file:
grease_file.write(grease)
def css_to_grease(self, css_filename, css, patterns):
includes = '\n'.join([f'// @include {p}' for p in patterns])
return (
'// ==UserScript==\n'
+ f'// @name Userstyle ({css_filename})\n'
+ includes + '\n'
+ '// ==/UserScript==\n'
+ f'GM_addStyle(`{css}`)'
)
def reload():
fifo = os.getenv('QUTE_FIFO')
if not fifo: return
with open(fifo, 'w') as feefifofam:
feefifofam.write('greasemonkey-reload -q\n')
feefifofam.write('reload\n')
if __name__ == "__main__":
RebuildGreaseStyles().create_grease_scripts_from_css_files()
reload()