This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathhelpers.py
78 lines (58 loc) · 2.21 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
My helper scripts for setting up qtile
"""
from libqtile.config import Key
import subprocess
import os
from settings import SCRIPT_DIR
def run(cmd, with_output=False):
"""
Run an external command as a subprocess, optionally return the output
"""
if with_output:
result = subprocess.run(cmd.split(), stdout=subprocess.PIPE)
return result.stdout.decode()
else:
subprocess.run(cmd.split())
def wallpaper(fname):
"""Set the wallpaper using feh"""
run("feh --bg-fill /home/innes/Pictures/Wallpapers/%s" % fname)
def script(fname):
"""Get the path of a script in the scripts directory"""
return os.path.expanduser(SCRIPT_DIR + fname)
def run_script(fname, with_output=False):
"""Run a script from my scripts directory"""
return run(script(fname), with_output=with_output)
def poll_func(script_name):
"""Used in generating the status bar"""
def poll():
return run_script(script_name, with_output=True)
return poll
# XXX : Ah, looks like this is a thing already...!
def ez_keys(key_bindings):
"""
Simplify the declaration of key bindings:
Before :: Key([mod, "shift"], "slash", lazy.layout.maximise())
After :: ("M-S-/", lazy.layout.maximise())
"""
modifiers = {"M": "mod4", "A": "mod1", "S": "shift", "C": "control"}
special_chars = {
"/": "slash", "\\": "backslash", ";": "semicolon", "`": "grave",
"[": "bracketleft", "]": "bracketright", "Esc": "Escape",
",": "comma", ".": "period", "-": "minus", "=": "equal",
"del": "Delete", "bckspc": "Backspace", "ret": "Return",
"'": "quoteleft", "#": "numbersign"
}
new_bindings = []
for spec, *actions in key_bindings:
# Only the last key is pressed, the rest are held as modifiers
*held, pressed = spec.split("-")
# Expand the shorthands
held = [modifiers.get(h, h) for h in held]
pressed = special_chars.get(pressed, pressed)
# Build the binding
new_bindings.append(Key(held, pressed, *actions))
return new_bindings
def notify(msg):
"""Send a notification. Used mainly for debugging config."""
run('notify-send "qtile" "%s"' % msg, with_output=False)