From a2e749cafe422e3f8a41768e839d6d7c5a1868a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= Date: Fri, 11 Aug 2017 16:56:23 +0200 Subject: [PATCH] Provide a host variable for targets Now, you can use `${host}` in your `target=`, enabling wildcard matches in the ini, so that one ini entry can match mutliple hosts with different passwords successfully. fixes #7 --- README.md | 7 +++++++ pass-git-helper | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd34643..d1a13ec 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,13 @@ As a consequence, in case you want to use the same account for all github projec [github.com*] target=dev/github ``` +The host can be used as a variable to address a pass entry. +This is especially helpful for wildcard matches: +```ini +[*] +target=git-logins/${host} +``` +The above configuration directive will lead to any host that did not match any previous section in the ini file to being looked up under the `git-logins` directory in your passwordstore. ## Passwordstore Layout diff --git a/pass-git-helper b/pass-git-helper index 9c4c20b..aaa8558 100755 --- a/pass-git-helper +++ b/pass-git-helper @@ -109,7 +109,7 @@ def get_password(request, mapping): LOGGER.debug('Section "%s" matches requested host "%s"', section, host) # TODO handle exceptions - pass_target = mapping.get(section, 'target') + pass_target = mapping.get(section, 'target').replace("${host}", host) skip_password_chars = mapping.getint( section, 'skip_password', fallback=0) skip_username_chars = mapping.getint(