diff options
| author | Andrew Guschin <saintruler@gmail.com> | 2021-05-10 14:44:07 +0400 |
|---|---|---|
| committer | Andrew Guschin <saintruler@gmail.com> | 2021-05-10 14:44:07 +0400 |
| commit | 40ce35bd2f379f2c30e51173752926f8c620ffd6 (patch) | |
| tree | d8bb4e1651758edd2af52e4b0a4b40c3c0f13c0e /.local/bin/lemonbar/modules | |
| parent | 2f6db370d4086eca956279ea41cd305b474f9caf (diff) | |
Changed window manager to bspwm and added custom config for lemonbar
Diffstat (limited to '.local/bin/lemonbar/modules')
| -rw-r--r-- | .local/bin/lemonbar/modules/battery.py | 11 | ||||
| -rw-r--r-- | .local/bin/lemonbar/modules/clock.py | 6 | ||||
| -rw-r--r-- | .local/bin/lemonbar/modules/language.py | 10 | ||||
| -rw-r--r-- | .local/bin/lemonbar/modules/updates.py | 48 | ||||
| -rw-r--r-- | .local/bin/lemonbar/modules/volume.py | 93 |
5 files changed, 168 insertions, 0 deletions
diff --git a/.local/bin/lemonbar/modules/battery.py b/.local/bin/lemonbar/modules/battery.py new file mode 100644 index 0000000..cb93f03 --- /dev/null +++ b/.local/bin/lemonbar/modules/battery.py @@ -0,0 +1,11 @@ +def read_file(filename): + with open(filename) as f: + return f.read().strip() + +def callback(): + battery = "BAT0" + now = int(read_file(f"/sys/class/power_supply/{battery}/energy_now")) + full = int(read_file(f"/sys/class/power_supply/{battery}/energy_full")) + percent = round(now / full * 100) + return f"BAT: {percent}%" + diff --git a/.local/bin/lemonbar/modules/clock.py b/.local/bin/lemonbar/modules/clock.py new file mode 100644 index 0000000..c4dc713 --- /dev/null +++ b/.local/bin/lemonbar/modules/clock.py @@ -0,0 +1,6 @@ +from time import strftime + + +def callback(): + clock = strftime("%d %b (%a) %H:%M") + return f"CLK: {clock}" diff --git a/.local/bin/lemonbar/modules/language.py b/.local/bin/lemonbar/modules/language.py new file mode 100644 index 0000000..50058c8 --- /dev/null +++ b/.local/bin/lemonbar/modules/language.py @@ -0,0 +1,10 @@ +from subprocess import run as _run + + +def run(command): + return _run(command.split(), capture_output=True).stdout.decode().strip() + + +def callback(): + name = run('xkblayout-state print "%s"').strip('"') + return f"LNG: {name.upper()}" diff --git a/.local/bin/lemonbar/modules/updates.py b/.local/bin/lemonbar/modules/updates.py new file mode 100644 index 0000000..67c8e93 --- /dev/null +++ b/.local/bin/lemonbar/modules/updates.py @@ -0,0 +1,48 @@ +from subprocess import run as _run +from time import time + + +def run(command): + return _run(command.split(), capture_output=True).stdout.decode().strip() + + +def pacman_count(): + cnt = 0 + for line in run('pacman -Qu').split("\n"): + if "[ignored]" not in line: + cnt += 1 + return cnt + + +def yay_count(): + cnt = 0 + for line in run('yay -Qau').split("\n"): + if "[ignored]" not in line: + cnt += 1 + return cnt + + +def callback(): + tmp_file = "/tmp/lemonbar/updates" + try: + with open(tmp_file) as f: + data = f.read().split() + except FileNotFoundError: + data = '' + + try: + timestamp = float(data[0]) + except (ValueError, IndexError): + timestamp = 0 + + if time() - timestamp > 900: + pacman = pacman_count() + aur = yay_count() + with open(tmp_file, "w") as f: + f.write(f"{time()} {pacman} {aur}") + else: + pacman = data[1] + aur = data[2] + + return f"UPD: {pacman}+{aur}" + diff --git a/.local/bin/lemonbar/modules/volume.py b/.local/bin/lemonbar/modules/volume.py new file mode 100644 index 0000000..f911571 --- /dev/null +++ b/.local/bin/lemonbar/modules/volume.py @@ -0,0 +1,93 @@ +from subprocess import run as _run +import re + + +def run(command): + return _run(command.split(), capture_output=True).stdout.decode().strip() + + +def get_default_sink(): + default_name = None + for line in run("pactl info").split("\n"): + key, val = line.split(": ") + if key == "Default Sink": + default_name = val + break + + if default_name is None: + return None + + for sid, sink in get_sinks().items(): + if sink["Name"] == default_name: + return sink + return None + + +def get_sinks(): + SINK, PARAMS, PARAM = 0, 1, 2 + parsing = SINK + + re_param_str = re.compile("(.+?): (.*)") + re_param_list = re.compile("(.+?):") + + current_sink = None + current_param = None + + sinks = {} + for line in run("pactl list sinks").split("\n"): + indent = line.count("\t") + line = line.strip() + + if parsing == SINK: + if line.startswith("Sink"): + n = line.split()[1] + sinks[n] = {} + current_sink = sinks[n] + + parsing = PARAMS + + elif parsing == PARAMS: + if line == '': + parsing = SINK + continue + + match = re_param_str.match(line) + if indent == 1 and match is not None: + name, value = match.groups() + current_param = name + current_sink[name] = value + continue + + match = re_param_list.match(line) + if indent == 1 and match is not None: + name = match.group(1) + current_param = name + current_sink[name] = [] + continue + + value = current_sink[name] + if isinstance(value, str): + current_sink[name] = [value] + + current_sink[name].append(line) + + return sinks + + +def get_sink_volume(sink): + if sink is None: + return "None" + if sink["Mute"] == "yes": + return "Muted" + + match = re.search(r"(\d+?)%", sink["Volume"][0]) + if match is not None: + return f"{match.groups()[0]}%" + + +def callback(): + def_sink = get_default_sink() + vol = get_sink_volume(def_sink) + + return f"VOL: {vol}" + |