Commit e4b18fa5 authored by Robert Labudda's avatar Robert Labudda
Browse files

dpass: prefer rofi, fallback to dmenu

parent 1fb132ae
......@@ -10,8 +10,9 @@ import argparse
import subprocess
import webbrowser
import time
import shutil
__version__ = '0.1.2'
__version__ = '0.1.3'
DMENUOPTS = ['-nb', '#93a1a1',
......@@ -21,6 +22,10 @@ DMENUOPTS = ['-nb', '#93a1a1',
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--select',
action="store_true",
default=False,
help="Select the mode to run dpass in with a menu")
parser.add_argument('-t', '--type',
action="store_true",
default=False,
......@@ -55,6 +60,33 @@ parser.add_argument('-k', '--key-delay',
args = parser.parse_args(sys.argv[1:])
# find the best dmenu option
dmenuprog = ["dmenu"]
if len(shutil.which("rofi")) > 0:
dmenuprog = ["rofi", "-dmenu"]
else:
dmenuprog += DMENUOPTS
if args.select:
entries = {'Type password': ['-t'],
'Type username': ['-i'],
'Copy password to clipboard': [],
}
with subprocess.Popen(dmenuprog + ['-i', '-p', 'gopass'],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE) as dmenu:
dmenu.stdin.write(bytes("\n".join(entries.keys()), "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)
args = parser.parse_args(entries[selection])
# get all options from gopass
with subprocess.Popen(["gopass", "list", "--flat"], stdout=subprocess.PIPE) as gopass:
......@@ -81,10 +113,10 @@ elif args.otp:
prompt = 'totp'
elif args.user_id:
prompt = 'user id'
dmenuprog += ["-i", "-p", prompt]
# ask the user to select the entry
with subprocess.Popen(["dmenu", "-i", "-p", prompt] + DMENUOPTS,
with subprocess.Popen(dmenuprog,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE) as dmenu:
dmenu.stdin.write(bytes("\n".join(entries) + "\n", 'utf-8'))
......@@ -115,7 +147,7 @@ def xdo(*params):
def xtype(*params):
timeout = str(max(0, args.key_delay))
xdo('type', '--delay', timeout, *params)
xdo('type', '--delay', timeout, '--', *params)
def enter():
......
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