blob: 9fdb4a4869bf0b892ffe70431c7c26f045d9ee01 (
plain) (
blame)
| 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
 | #!/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 "$@"
 |