24 lines
814 B
Python
Executable file
24 lines
814 B
Python
Executable file
#!/usr/bin/python
|
|
|
|
# runs dmenu with the first value of $@ as promt, each even value of $@ as option and the following odd value as command for that option
|
|
# for example $ ./multipromt "Power Button Pressed?" "Shutdown" "sudo shutdown now" "Reboot" "sudo reboot now" "Exit I3wm" "i3-msg exit"
|
|
|
|
import subprocess
|
|
from sys import argv
|
|
|
|
def pairs(iterable):
|
|
return zip(iterable[::2], iterable[1::2])
|
|
|
|
def demnu_select(options, promt=""):
|
|
return subprocess.run(["dmenu", "-p", promt], stdout=subprocess.PIPE, input="\n".join(options).encode("UTF-8")).stdout.decode().strip()
|
|
|
|
def main():
|
|
cmds = dict(pairs(["Abort", ""] + argv[2:]))
|
|
selected = demnu_select(cmds, argv[1])
|
|
cmd = cmds.get(selected, "").split()
|
|
if len(cmd) > 0:
|
|
subprocess.run(cmd)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|