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
1 changed files with 11 additions and 6 deletions

View File

@ -11,13 +11,19 @@ PASSWORD_STORE = PosixPath(
os.environ.get("PASSWORD_STORE_DIR", PosixPath("~/.password-store").expanduser())
)
ALIASES = {
"salt": "cms-net-svcs",
}
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:
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)
if ssh_match:
raw_server_name = ssh_match.group("server")
server_name = ALIASES.get(raw_server_name, raw_server_name)
server_name = alias(ssh_match.group("server"))
notify(f"Matched server '{server_name}'", f"Window name: {window_name}")