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):
|
def alias(server_name):
|
||||||
match server_name.rpartition("@"):
|
match server_name.rpartition("@"):
|
||||||
case [_, _, "salt"]:
|
case [user, at, "salt"]:
|
||||||
return "cms/*cms-net-svcs"
|
return f"cms/{user}{at}cms-net-svcs"
|
||||||
case [_, _, ("iPad1" | "iPad2" | "iPad3")]:
|
case [user, at, ("iPad1" | "iPad2" | "iPad3")]:
|
||||||
return "cms/*ipads"
|
return f"cms/{user}{at}ipads"
|
||||||
case [_, _, ("octopi-taz-6" | "octopi-lulzbot-mini")]:
|
case [user, at, ("octopi-taz-6" | "octopi-lulzbot-mini")]:
|
||||||
return "cms/*octopi"
|
return f"cms/{user}{at}octopi"
|
||||||
case _:
|
case _:
|
||||||
return server_name
|
return f"**/{server_name}"
|
||||||
|
|
||||||
|
|
||||||
def notify(summary: str, body: str) -> None:
|
def notify(summary: str, body: str) -> None:
|
||||||
@ -42,10 +42,11 @@ def get_password(password_name: str) -> None:
|
|||||||
return password
|
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(
|
files = chain(
|
||||||
PASSWORD_STORE.glob(f"servers/**/{server_name}.gpg"),
|
PASSWORD_STORE.glob(str(path)),
|
||||||
PASSWORD_STORE.glob(f"servers/**/*@{server_name}.gpg"),
|
PASSWORD_STORE.glob(str(path.with_name("*@" + path.name))),
|
||||||
)
|
)
|
||||||
file_list = list(
|
file_list = list(
|
||||||
dict.fromkeys(str(f.relative_to(PASSWORD_STORE).with_suffix("")) for f in files)
|
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}")
|
notify(f"Matched server '{server_name}'", f"Window name: {window_name}")
|
||||||
|
|
||||||
select_and_type(server_name)
|
select_and_type(Path(server_name))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
notify("Window name did not match any rules", f"Window name: {window_name}")
|
notify("Window name did not match any rules", f"Window name: {window_name}")
|
||||||
|
Loading…
Reference in New Issue
Block a user