diff options
Diffstat (limited to 'git-credential-pass')
-rwxr-xr-x | git-credential-pass | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/git-credential-pass b/git-credential-pass new file mode 100755 index 0000000..0db00e9 --- /dev/null +++ b/git-credential-pass @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +from parse import search +from os import environ, path +from sys import stdin +from gnupg import GPG + + +if 'PASSWORD_STORE_DIR' in environ: + pass_dir = environ['PASSWORD_STORE_DIR'] +else: + pass_dir = path.join(path.expanduser('~'), '.password-store') + +file_path = path.join(pass_dir, 'git') + +data = stdin.read() +if 'username' in data: + (protocol, host, username) = search('protocol={}\nhost={}\nusername={}\n', data) + file_path = path.join(file_path, host, username) + '.gpg' +else: + (protocol, host) = search('protocol={}\nhost={}\n', data) + file_path = path.join(file_path, host, 'default') + '.gpg' + +with open(file_path, 'rb') as fp: + encrypted = fp.read() + +gpg = GPG() +gpg.use_agent = True +password = str(gpg.decrypt(encrypted)).splitlines()[0] + +output = ('protocol={}\n' + 'host={}\n' + 'username={}\n' + 'password={}').format(protocol, host, username, password) + +print(output) |