From 8260316a1d3b9a0bc918988375782c019c1a81be Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 4 Nov 2023 19:27:28 +0530 Subject: bin/wobload: refactor --- .local/bin/wobload | 61 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) (limited to '.local/bin/wobload') diff --git a/.local/bin/wobload b/.local/bin/wobload index 0d8b121..599024c 100755 --- a/.local/bin/wobload +++ b/.local/bin/wobload @@ -30,39 +30,38 @@ render() echo "${1%%.*}" > "$wobpipe" } -main() -{ - exe="$1" - shift +######## +# MAIN # +######## - if [ -z "$exe" ]; then - usage - exit - elif [ ! -p "$wobpipe" ]; then - err "$wobpipe: named pipe does not exist" - exit 1 - elif ! command -v "$exe" > /dev/null; then - err "${exe}: command not found" - exit 127 - fi +exe="$1" +shift - case "$exe" in - "wpctl") - wpctl "$@" +if [ -z "$exe" ]; then + usage + exit +elif [ ! -p "$wobpipe" ]; then + err "$wobpipe: named pipe does not exist" + exit 1 +elif ! command -v "$exe" > /dev/null; then + err "${exe}: command not found" + exit 127 +fi - data="$(wpctl get-volume "@DEFAULT_AUDIO_SINK@")" - render "$(echo "${data##* } * 100" | bc)" - ;; - "brightnessctl") - brightnessctl "$@" +case "$exe" in +"wpctl") + wpctl "$@" - data="$(brightnessctl info | grep -o '[0-9]*%')" - render "${data%\%}" - ;; - *) - err "${exe}: not implemented" - "$exe" "$@" - esac -} + data="$(wpctl get-volume "@DEFAULT_AUDIO_SINK@")" + render "$(echo "${data##* } * 100" | bc)" + ;; +"brightnessctl") + brightnessctl "$@" -main "$@" + data="$(brightnessctl info | grep -o '[0-9]*%')" + render "${data%\%}" + ;; +*) + err "${exe}: not implemented" + "$exe" "$@" +esac -- cgit v1.2.3