summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-05-03 11:19:04 +0530
committersinanmohd <sinan@firemail.cc>2023-05-03 11:25:22 +0530
commitd28f163871980205c127a4035bebca4e9363dd3f (patch)
tree3ba14450b33fc174478fa0f6d236555e4672c656
parent24abc523046749e510b3b61fff97b067677b379b (diff)
wobload: initial commit
a helper script for wob the wayland overlay bar
-rwxr-xr-x.local/bin/wobload69
1 files changed, 69 insertions, 0 deletions
diff --git a/.local/bin/wobload b/.local/bin/wobload
new file mode 100755
index 0000000..9fdb4a4
--- /dev/null
+++ b/.local/bin/wobload
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+wobpipe="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/wobpipe"
+
+usage()
+{
+ cat <<- EOF
+ Usage: ${0##*/} [cmd]
+ A helper script for wob the wayland overlay bar
+
+ Example:
+ ${0##*/} wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
+
+ EOF
+}
+
+err()
+{
+ : "${1:?}"
+
+ printf "\033[31;1merr: %b\033[0m\n" "$1"
+ command -v notify-send > /dev/null &&
+ notify-send " wob loader" "$1"
+}
+
+render()
+{
+ : "${1:?}"
+
+ echo "${1%%.*}" > "$wobpipe"
+}
+
+main()
+{
+ exe="$1" && [ -z "$exe" ] &&
+ usage && exit
+
+ if [ ! -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 1
+ fi
+
+ shift
+ case "$exe" in
+ "wpctl")
+ wpctl "$@"
+
+ data="$(wpctl get-volume "@DEFAULT_AUDIO_SINK@")"
+ render "$(echo "${data##* } * 100" | bc)"
+ ;;
+ "brightnessctl")
+ brightnessctl "$@"
+
+ data="$(brightnessctl info | grep -o '[0-9]*%')"
+ render "${data%\%}"
+ ;;
+ "")
+ usage
+ ;;
+ *)
+ err "${exe}: not implemented"
+ "$exe" "$@"
+ esac
+}
+
+main "$@"