pass_typer: Improve matching for aliased servers
This commit is contained in:
parent
ca3308dd18
commit
ca7fb74daa
@ -16,14 +16,14 @@ cmd = partial(subprocess.run, capture_output=True, encoding="ascii")
|
||||
|
||||
def alias(server_name):
|
||||
match server_name.rpartition("@"):
|
||||
case [_, _, "salt"]:
|
||||
return "cms/*cms-net-svcs"
|
||||
case [_, _, ("iPad1" | "iPad2" | "iPad3")]:
|
||||
return "cms/*ipads"
|
||||
case [_, _, ("octopi-taz-6" | "octopi-lulzbot-mini")]:
|
||||
return "cms/*octopi"
|
||||
case [user, at, "salt"]:
|
||||
return f"cms/{user}{at}cms-net-svcs"
|
||||
case [user, at, ("iPad1" | "iPad2" | "iPad3")]:
|
||||
return f"cms/{user}{at}ipads"
|
||||
case [user, at, ("octopi-taz-6" | "octopi-lulzbot-mini")]:
|
||||
return f"cms/{user}{at}octopi"
|
||||
case _:
|
||||
return server_name
|
||||
return f"**/{server_name}"
|
||||
|
||||
|
||||
def notify(summary: str, body: str) -> None:
|
||||
@ -42,10 +42,11 @@ def get_password(password_name: str) -> None:
|
||||
return password
|
||||
|
||||
|
||||
def select_and_type(server_name: str) -> None:
|
||||
def select_and_type(server_name: Path) -> None:
|
||||
path = ("servers" / server_name).with_suffix(".gpg")
|
||||
files = chain(
|
||||
PASSWORD_STORE.glob(f"servers/**/{server_name}.gpg"),
|
||||
PASSWORD_STORE.glob(f"servers/**/*@{server_name}.gpg"),
|
||||
PASSWORD_STORE.glob(str(path)),
|
||||
PASSWORD_STORE.glob(str(path.with_name("*@" + path.name))),
|
||||
)
|
||||
file_list = list(
|
||||
dict.fromkeys(str(f.relative_to(PASSWORD_STORE).with_suffix("")) for f in files)
|
||||
@ -65,7 +66,7 @@ if ssh_match:
|
||||
|
||||
notify(f"Matched server '{server_name}'", f"Window name: {window_name}")
|
||||
|
||||
select_and_type(server_name)
|
||||
select_and_type(Path(server_name))
|
||||
|
||||
else:
|
||||
notify("Window name did not match any rules", f"Window name: {window_name}")
|
||||
|
Loading…
Reference in New Issue
Block a user