Commit 81f3692b authored by Robert Labudda's avatar Robert Labudda
Browse files

dpass

parent 8be4a22b
#!/usr/bin/env python3
import sys
import argparse
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--type',
action="store_true",
default=False,
help="Type password instead of copying it into the clipboard")
parser.add_argument('-l', '--login',
action="store_true",
default=False,
help="Type a login (username, tab, password, enter)")
args = parser.parse_args(sys.argv[1:])
# get all options from gopass
with subprocess.Popen(["gopass", "list", "--flat"], stdout=subprocess.PIPE) as gopass:
rawentries = gopass.stdout.read()
if rawentries is None:
sys.exit(-1)
entries = []
for line in str(rawentries, "utf-8").split("\n"):
if len(line) > 0:
entries.append(line)
# ask the user to select the entry
with subprocess.Popen(["dmenu", "-i"], stdout=subprocess.PIPE, stdin=subprocess.PIPE) as dmenu:
dmenu.stdin.write(bytes("\n".join(entries) + "\n", 'utf-8'))
dmenu.stdin.close()
selection = dmenu.stdout.read()
if selection is not None:
selection = str(selection, 'utf-8').strip()
if selection is None or selection not in entries:
sys.exit(-1)
# copy or type
if args.type:
with subprocess.Popen(["gopass", "show", "--force", "--password", selection], stdout=subprocess.PIPE) as gopass:
pwd = str(gopass.stdout.read(), 'utf-8')
with subprocess.Popen(["xdotool", "type", "--delay", "60", pwd]) as dotool:
pass
with subprocess.Popen(["xdotool", "key", "Return"]) as dotool:
pass
elif args.login:
with subprocess.Popen(["gopass", "show", "--force", selection], stdout=subprocess.PIPE) as gopass:
blob = str(gopass.stdout.read(), 'utf-8')
if blob is None:
sys.exit(-1)
pwd, rest = blob.split("\n", 1)
userid = None
for line in rest.split("\n"):
if ':' in line and line.split(':', 1)[0].lower() in ['user', 'username', 'login', 'uid']:
userid = line.split(':', 1)[1].strip()
break
if userid is None:
sys.exit(-1)
with subprocess.Popen(["xdotool", "type", "--delay", "60", userid]) as dotool:
pass
with subprocess.Popen(["xdotool", "key", "Tab"]) as dotool:
pass
with subprocess.Popen(["xdotool", "type", "--delay", "60", pwd]) as dotool:
pass
with subprocess.Popen(["xdotool", "key", "Return"]) as dotool:
pass
else:
with subprocess.Popen(["gopass", "--clip", selection], stdout=subprocess.PIPE) as gopass:
pass
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment