dotfiles/i3/scripts/dmenu/Dmenu.py

25 lines
582 B
Python
Raw Normal View History

2018-04-05 05:30:27 +02:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import json
import subprocess
class Dmenu(object):
def __init__(self, items: list):
with open(os.path.dirname(sys.argv[0]) + "/dmenu.json") as fp:
self._dmenu = json.load(fp)["dmenu"]
self._items = items
def run(self):
"""Returns (exitCode, stdout)"""
2018-06-10 21:59:13 +02:00
p1 = subprocess.run(
self._dmenu,
input="\n".join(self._items),
encoding="utf-8",
stdout=subprocess.PIPE,
)
2018-04-05 05:30:27 +02:00
return (p1.returncode, p1.stdout)