From abbd3df78bbf9e9f1d875fb551c7a2b4126e4cd6 Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Sun, 22 Jun 2025 14:34:42 -0400 Subject: [PATCH] Minor EWW script cleanup --- eww/scripts/adjust-volume.sh | 9 +++------ eww/scripts/backlight.sh | 12 ++++-------- eww/scripts/get-audio-device-id.sh | 15 +++++---------- eww/scripts/network-statistics-shell.sh | 2 +- eww/scripts/network-statistics.py | 20 ++++++++++---------- 5 files changed, 23 insertions(+), 35 deletions(-) diff --git a/eww/scripts/adjust-volume.sh b/eww/scripts/adjust-volume.sh index 2dc9f06..9001c4f 100755 --- a/eww/scripts/adjust-volume.sh +++ b/eww/scripts/adjust-volume.sh @@ -3,10 +3,7 @@ DELTA="1%" case "$1" in - "up") pactl set-sink-volume @DEFAULT_SINK@ +"$DELTA" - ;; - "down") pactl set-sink-volume @DEFAULT_SINK@ -"$DELTA" - ;; - *) exit 1 - ;; + up) pactl set-sink-volume @DEFAULT_SINK@ +"$DELTA";; + down) pactl set-sink-volume @DEFAULT_SINK@ -"$DELTA";; + *) exit 1;; esac diff --git a/eww/scripts/backlight.sh b/eww/scripts/backlight.sh index eb9b8c1..e634f88 100755 --- a/eww/scripts/backlight.sh +++ b/eww/scripts/backlight.sh @@ -3,12 +3,8 @@ DELTA="1%" case "$1" in - up) brightnessctl -m -c backlight set +"$DELTA" - ;; - down) brightnessctl -m -c backlight set "$DELTA"- - ;; - get) brightnessctl -m -c backlight get - ;; - *) echo "Unrecognized command"; exit 1 - ;; + up) brightnessctl -m -c backlight set +"$DELTA";; + down) brightnessctl -m -c backlight set "$DELTA"-;; + get) brightnessctl -m -c backlight get;; + *) echo "Unrecognized command"; exit 1;; esac diff --git a/eww/scripts/get-audio-device-id.sh b/eww/scripts/get-audio-device-id.sh index 8b13c59..7c29c8e 100755 --- a/eww/scripts/get-audio-device-id.sh +++ b/eww/scripts/get-audio-device-id.sh @@ -11,14 +11,9 @@ get_or_default() { } case "$1" in - "headphones") echo "$DEFAULT_HEADPHONES" # TODO: Figure out generic regex string to match headphones - ;; - "speakers") get_or_default 'sinks' 'HiFi__Headphones__sink' "$DEFAULT_SPEAKERS" - ;; - "headphone_mic") echo "$DEFAULT_HEADPHONE_MIC" # TODO: Figure out generic regex string to match headphone mic - ;; - "blue_mic") get_or_default 'sources' 'Generic_Blue_Microphones[a-zA-Z0-9_.\\-]+\\.analog-stereo$' "$DEFAULT_BLUE_MIC" - ;; - *) echo "Device name '$1' not recognized"; exit 1 - ;; + headphones) echo "$DEFAULT_HEADPHONES";; # TODO: Figure out generic regex string to match headphones + speakers) get_or_default 'sinks' 'HiFi__Headphones__sink' "$DEFAULT_SPEAKERS";; + headphone_mic) echo "$DEFAULT_HEADPHONE_MIC";; # TODO: Figure out generic regex string to match headphone mic + blue_mic) get_or_default 'sources' 'Generic_Blue_Microphones[a-zA-Z0-9_.\\-]+\\.analog-stereo$' "$DEFAULT_BLUE_MIC";; + *) echo "Device name '$1' not recognized"; exit 1;; esac diff --git a/eww/scripts/network-statistics-shell.sh b/eww/scripts/network-statistics-shell.sh index 7ff6043..57cd8ba 100755 --- a/eww/scripts/network-statistics-shell.sh +++ b/eww/scripts/network-statistics-shell.sh @@ -1,4 +1,4 @@ #!/bin/env sh # EWW doesn't seem to like listening to Python scripts directly, but this wrapper seems to work fine -"$(dirname "$0")"/network-statistics $@ +"$(dirname "$0")"/network-statistics "$@" diff --git a/eww/scripts/network-statistics.py b/eww/scripts/network-statistics.py index bf46e1f..6d7a06b 100755 --- a/eww/scripts/network-statistics.py +++ b/eww/scripts/network-statistics.py @@ -9,14 +9,14 @@ from typing import Literal, NoReturn def get_interfaces() -> list[Path]: - return list(Path("/sys/class/net/").glob("*")) + return list(Path("/sys/class/net/").iterdir()) class TransferredBytes: def __init__(self, interface: Path, statistic: Literal["tx"] | Literal["rx"]) -> None: - self._statistic = interface / f"statistics/{statistic}_bytes" - self._current = int(self._statistic.read_text()) - self._previous = self._current + self._statistic: Path = interface / f"statistics/{statistic}_bytes" + self._current: int = int(self._statistic.read_text()) + self._previous: int = self._current def update(self) -> None: self._previous = self._current @@ -28,7 +28,7 @@ class TransferredBytes: class Status: def __init__(self, interface: Path) -> None: - self._statistic = interface / "operstate" + self._statistic: Path = interface / "operstate" def up(self) -> bool: return self._statistic.read_text().strip() == "up" @@ -56,10 +56,10 @@ def format_bytes(num: float) -> str: class Interface: def __init__(self, location: Path) -> None: - self._location = location - self._tx = TransferredBytes(location, "tx") - self._rx = TransferredBytes(location, "rx") - self._status = Status(location) + self._location: Path = location + self._tx: TransferredBytes = TransferredBytes(location, "tx") + self._rx: TransferredBytes = TransferredBytes(location, "rx") + self._status: Status = Status(location) @property def name(self) -> str: @@ -84,7 +84,7 @@ class Interface: class Statistics: def __init__(self) -> None: - self._interfaces = [Interface(location) for location in get_interfaces()] + self._interfaces: list[Interface] = [Interface(location) for location in get_interfaces()] def update(self) -> None: for interface in self._interfaces: