#!/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)