pass_typer: Use more flexible match expression for server aliases

Also add ipad aliases
This commit is contained in:
Adam Goldsmith 2022-03-16 20:53:22 -04:00
parent af00393233
commit 196b9802ad

View File

@ -11,13 +11,19 @@ PASSWORD_STORE = PosixPath(
os.environ.get("PASSWORD_STORE_DIR", PosixPath("~/.password-store").expanduser()) os.environ.get("PASSWORD_STORE_DIR", PosixPath("~/.password-store").expanduser())
) )
ALIASES = {
"salt": "cms-net-svcs",
}
cmd = partial(subprocess.run, capture_output=True, encoding="ascii") cmd = partial(subprocess.run, capture_output=True, encoding="ascii")
def alias(server_name):
match server_name:
case "salt":
return "cms-net-svcs"
case "iPad1" | "iPad2" | "iPad3":
return "ipads"
case _:
return server_name
def notify(summary: str, body: str) -> None: def notify(summary: str, body: str) -> None:
subprocess.run(["notify-send", summary, body]) subprocess.run(["notify-send", summary, body])
@ -49,8 +55,7 @@ window_name = cmd(["xdotool", "getactivewindow", "getwindowname"]).stdout.strip(
ssh_match = re.search(":(mosh|ssh) (?P<server>.*)", window_name) ssh_match = re.search(":(mosh|ssh) (?P<server>.*)", window_name)
if ssh_match: if ssh_match:
raw_server_name = ssh_match.group("server") server_name = alias(ssh_match.group("server"))
server_name = ALIASES.get(raw_server_name, raw_server_name)
notify(f"Matched server '{server_name}'", f"Window name: {window_name}") notify(f"Matched server '{server_name}'", f"Window name: {window_name}")