From af003932330dd970dbd8b84dba40aedc49e0dc7d Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 16 Mar 2022 20:52:31 -0400 Subject: [PATCH] pass_typer: Match passwords of form username@server --- .config/i3/pass_typer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.config/i3/pass_typer.py b/.config/i3/pass_typer.py index c27f63a..ec2e818 100755 --- a/.config/i3/pass_typer.py +++ b/.config/i3/pass_typer.py @@ -4,6 +4,7 @@ import os import re import subprocess from functools import partial +from itertools import chain from pathlib import PosixPath PASSWORD_STORE = PosixPath( @@ -33,9 +34,10 @@ def get_password(password_name: str) -> None: return password -def select_and_type(glob: str) -> None: - files = PASSWORD_STORE.glob(glob) - file_list = [str(f.relative_to(PASSWORD_STORE).with_suffix("")) for f in files] +def select_and_type(server_name: str) -> None: + files = chain(PASSWORD_STORE.glob(f"servers/**/{server_name}.gpg"), + PASSWORD_STORE.glob(f"servers/**/*@{server_name}.gpg")) + file_list = {str(f.relative_to(PASSWORD_STORE).with_suffix("")) for f in files} selected = rofi_select(file_list) password = get_password(selected) @@ -52,7 +54,7 @@ if ssh_match: notify(f"Matched server '{server_name}'", f"Window name: {window_name}") - select_and_type(f"servers/**/{server_name}.gpg") + select_and_type(server_name) else: notify("Window name did not match any rules", f"Window name: {window_name}")