Browse Source

dmenu_multicmd: some cleanup and config example

Von Random 1 month ago
parent
commit
6c3e745835
1 changed files with 19 additions and 13 deletions
  1. 19
    13
      dmenu_multicmd

+ 19
- 13
dmenu_multicmd View File

@@ -1,15 +1,26 @@
1 1
 #!/usr/bin/env python3
2 2
 #pylint: disable=C0111
3
-
4
-import os
3
+# config example (cmd_pre and cmd_post are optional):
4
+# ---
5
+# name: test
6
+# cmd_pre:
7
+#   - [/usr/bin/notify_send, 'I am precmd1!']
8
+#   - [/usr/bin/notify_send, 'I am precmd2!']
9
+# multicmd:
10
+#   selection1:
11
+#     - [/usr/bin/notify-send, 'I am command1 for selection1!']
12
+#     - [/usr/bin/notify-send, 'I am command2 for selection1!']
13
+#   selection2:
14
+#     - [/usr/bin/notify-send, 'I am command1 for selection2!']
15
+# cmd_post:
16
+#   - [/usr/bin/notify_send, 'I am postcmd1!']
17
+#   - [/usr/bin/notify_send, 'I am postcmd2!']
18
+# ---
5 19
 import subprocess
6 20
 import sys
7 21
 import yaml
8 22
 
9 23
 
10
-CONFIG_PATH = os.path.join(os.environ['HOME'], '.displayrc.yaml')
11
-
12
-
13 24
 def run_cmd(cmd, stdin=subprocess.PIPE, data=None):
14 25
     proc = subprocess.Popen(
15 26
         cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=stdin
@@ -27,7 +38,7 @@ def run_cmd(cmd, stdin=subprocess.PIPE, data=None):
27 38
 
28 39
 def run_multicmd(cmds):
29 40
     for cmd in cmds:
30
-        run_cmd(cmds[cmd])
41
+        run_cmd(cmd)
31 42
 
32 43
 
33 44
 def main():
@@ -39,14 +50,9 @@ def main():
39 50
     selection = run_cmd(dmenu_cmd, data=dmenu_opt).decode('UTF-8')
40 51
     if not selection in conf['multicmd']:
41 52
         sys.exit(1)
42
-
43
-    if 'cmd_pre' in conf:
44
-        run_multicmd(conf['cmd_pre'])
45
-
53
+    run_multicmd(conf.get('cmd_pre', tuple()))
46 54
     run_multicmd(conf['multicmd'][selection])
47
-
48
-    if 'cmd_post' in conf:
49
-        run_multicmd(conf['cmd_post'])
55
+    run_multicmd(conf.get('cmd_post', tuple()))
50 56
 
51 57
 if __name__ == '__main__':
52 58
     main()

Loading…
Cancel
Save