various tweaks and refactors
This commit is contained in:
parent
2fb479e4ec
commit
8e5f4e4d9e
7 changed files with 31 additions and 24 deletions
|
@ -20,7 +20,6 @@ import subprocess
|
|||
import sys
|
||||
import yaml
|
||||
|
||||
|
||||
def run_cmd(cmd, stdin=subprocess.PIPE, data=None):
|
||||
proc = subprocess.Popen(
|
||||
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=stdin
|
||||
|
@ -35,24 +34,22 @@ def run_cmd(cmd, stdin=subprocess.PIPE, data=None):
|
|||
sys.stderr.write('\n'.join(err_msg) + '\n')
|
||||
return stdout
|
||||
|
||||
|
||||
def run_multicmd(cmds):
|
||||
for cmd in cmds:
|
||||
run_cmd(cmd)
|
||||
|
||||
|
||||
def main():
|
||||
config_path = sys.argv[1]
|
||||
with open(config_path, mode='r') as config:
|
||||
conf = yaml.load(config.read())
|
||||
conf = yaml.safe_load(config.read())
|
||||
dmenu_cmd = ['/usr/bin/dmenu', '-p', conf.get('name', 'N/A')] + sys.argv[2:]
|
||||
dmenu_opt = '\n'.join(conf['multicmd']).encode()
|
||||
selection = run_cmd(dmenu_cmd, data=dmenu_opt).decode('UTF-8')
|
||||
#selection = sys.argv[2]
|
||||
if not selection in conf['multicmd']:
|
||||
sys.exit(1)
|
||||
run_multicmd(conf.get('cmd_pre', tuple()))
|
||||
run_multicmd(conf['multicmd'][selection])
|
||||
run_multicmd(conf.get('cmd_post', tuple()))
|
||||
cmds =\
|
||||
conf.get('cmd_pre', list()) +\
|
||||
conf['multicmd'][selection] +\
|
||||
conf.get('cmd_post', list())
|
||||
for cmd in cmds:
|
||||
run_cmd(cmd)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue