Update remap rules for windowname script

This commit is contained in:
ItsDrike 2024-06-21 02:39:01 +02:00
parent 2acdfac532
commit 47d070ce5e
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0

View file

@ -7,6 +7,7 @@ the window names. Window name and class are obtained from piped stdin, to preven
needlessly keep restarting this program, which takes a while due to the interpreter starting needlessly keep restarting this program, which takes a while due to the interpreter starting
overhead. overhead.
""" """
import json import json
import re import re
import sys import sys
@ -50,9 +51,9 @@ class RemapRule:
# Rules will be applied in specified order # Rules will be applied in specified order
REMAP_RULES: list[RemapRule] = [ REMAP_RULES: list[RemapRule] = [
RemapRule(r"", "", ""), RemapRule(r"", "", ""),
RemapRule(r"(.*) — Mozilla Firefox", "{}", "firefox"), RemapRule(r"(.*) — Mozilla Firefox", " {}", "firefox"),
RemapRule(r"Mozilla Firefox", "Mozilla Firefox", "firefox"), RemapRule(r"Mozilla Firefox", " Mozilla Firefox", "firefox"),
RemapRule(r"Alacritty", "Alacritty", "Alacritty"), RemapRule(r"Alacritty", " Alacritty", "Alacritty"),
RemapRule( RemapRule(
r"zsh;#toggleterm#1 - \(term:\/\/(.+)\/\/(\d+):(.+)\) - N?VIM", r"zsh;#toggleterm#1 - \(term:\/\/(.+)\/\/(\d+):(.+)\) - N?VIM",
" Terminal: {0}", " Terminal: {0}",
@ -63,13 +64,13 @@ REMAP_RULES: list[RemapRule] = [
RemapRule(r"(.+) - Discord", "{}", "discord"), RemapRule(r"(.+) - Discord", "{}", "discord"),
RemapRule(r"(?:\(\d+\) )?Discord \| (.+)", "{}", "vesktop"), RemapRule(r"(?:\(\d+\) )?Discord \| (.+)", "{}", "vesktop"),
RemapRule(r"(.+) - mpv", "{}", "mpv"), RemapRule(r"(.+) - mpv", "{}", "mpv"),
RemapRule(r"Stremio - (.+)", "Stremio - {}", r"(Stremio)|(com.stremio.stremio)"), RemapRule(r"Stremio - (.+)", " Stremio - {}", r"(Stremio)|(com.stremio.stremio)"),
RemapRule(r"Spotify", " Spotify", "Spotify"), RemapRule(r"Spotify((?: Premium)?)", " Spotify{}", "[Ss]potify"),
RemapRule(r"pulsemixer", "Pulsemixer"), RemapRule(r"pulsemixer", " Pulsemixer"),
RemapRule(r"(.*)", "{}", "Pcmanfm"), RemapRule(r"(.*)", "{}", "Pcmanfm"),
RemapRule(r"(.*)", "{}", "pcmanfm-qt"), RemapRule(r"(.*)", "{}", "pcmanfm-qt"),
# Needs to be last # Needs to be last
RemapRule(r"(.*)", "{}", "kitty"), RemapRule(r"(.*)", " {}", "kitty"),
] ]
MAX_LENGTH = 65 MAX_LENGTH = 65
@ -81,7 +82,9 @@ def iter_window() -> Iterator[tuple[str, str]]:
line = line.removesuffix("\n") line = line.removesuffix("\n")
els = line.split(",", maxsplit=1) els = line.split(",", maxsplit=1)
if len(els) != 2: if len(els) != 2:
raise ValueError(f"Expected 2 arguments from stdin line (name, class), but got {len(els)}") raise ValueError(
f"Expected 2 arguments from stdin line (name, class), but got {len(els)}"
)
yield els[1], els[0] yield els[1], els[0]