#!/usr/bin/env bash set -euo pipefail CONFIG_FILE="$HOME/.config/plasma-org.kde.plasma.desktop-appletsrc" CUSTOM_PRESET_DIR="$HOME/.config/panel-colorizer/presets/LogicDock" USER_BUILTIN_PRESET_DIR="$HOME/.local/share/plasma/plasmoids/luisbocanegra.panel.colorizer/contents/ui/presets/Dock" SYSTEM_BUILTIN_PRESET_DIR="/usr/share/plasma/plasmoids/luisbocanegra.panel.colorizer/contents/ui/presets/Dock" PRESET_DIR="$CUSTOM_PRESET_DIR" [[ -d "$PRESET_DIR" ]] || PRESET_DIR="$USER_BUILTIN_PRESET_DIR" [[ -d "$PRESET_DIR" ]] || PRESET_DIR="$SYSTEM_BUILTIN_PRESET_DIR" wait_for_plasma() { for _ in $(seq 1 30); do if qdbus6 org.kde.plasmashell /PlasmaShell org.freedesktop.DBus.Introspectable.Introspect >/dev/null 2>&1; then return 0 fi sleep 1 done return 1 } get_screen_count() { python - <<'PY' import re, subprocess text = subprocess.check_output(["kscreen-doctor", "-o"], text=True, errors="ignore") text = re.sub(r'\x1b\[[0-9;]*[A-Za-z]', '', text) blocks = re.split(r'(?=Output: )', text) count = 0 for block in blocks: if not block.startswith('Output: '): continue if re.search(r'^\s*enabled\s*$', block, re.M): count += 1 print(max(count, 1)) PY } get_bottom_colorizers() { python - <<'PY' import configparser, json, os, pathlib, re cfg = pathlib.Path(os.path.expanduser('~/.config/plasma-org.kde.plasma.desktop-appletsrc')) cp = configparser.RawConfigParser(interpolation=None) cp.optionxform = str cp.read(cfg) items = [] for sec in cp.sections(): m = re.fullmatch(r'Containments\]\[(\d+)', sec) if not m: continue cid = int(m.group(1)) if cp.get(sec, 'plugin', fallback='') != 'org.kde.panel': continue if cp.get(sec, 'location', fallback='') not in ('4', 'bottom'): continue for asec in cp.sections(): am = re.fullmatch(rf'Containments\]\[{cid}\]\[Applets\]\[(\d+)', asec) if not am: continue if cp.get(asec, 'plugin', fallback='') != 'luisbocanegra.panel.colorizer': continue aid = int(am.group(1)) items.append({'containment': cid, 'applet': aid}) print(json.dumps(sorted(items, key=lambda x: (x['containment'], x['applet'])))) PY } ensure_bottom_panels() { local screen_count="$1" local targets targets=$(python - <