my dotz
1#!/bin/sh
2#
3# simple pulse wrapper for controlling volume
4#
5# deps:
6# - pactl
7# - notify-send
8
9get_current_volume_percent() {
10 percent="$(pactl get-sink-volume @DEFAULT_SINK@ | awk '/Volume/ {print $5}')"
11 strip_perc="$(printf "%s" "$percent" | cut -d '%' -f 1)"
12 printf "%s" "$strip_perc"
13}
14
15notify_current_volume() {
16 vol="$(get_current_volume_percent)"
17 if [ "$vol" -gt 100 ]; then
18 # prevent volumes of >100% for the
19 # good of all ears
20 pactl set-sink-volume @DEFAULT_SINK@ 100%
21 notify-send '🔈 vol' --hint=int:value:100 -t 800 -h string:x-canonical-private-synchronous:anything
22 elif [ "$vol" -lt 0 ]; then
23 # prevent volumes of <0% for the
24 # good of all ... dog... whateij fiwjoefj
25 pactl set-sink-volume @DEFAULT_SINK@ 0%
26 notify-send '🔈 vol' --hint=int:value:0 -t 800 -h string:x-canonical-private-synchronous:anything
27 else
28 notify-send '🔈 vol' --hint=int:value:"$vol" -t 800 -h string:x-canonical-private-synchronous:anything
29 fi
30}
31
32case "$1" in
33 ls|list)
34 pactl list short sinks | awk '{print $1" "$2}'
35 ;;
36 set|use)
37 pactl set-default-sink "$2"
38 ;;
39 [0-9]*)
40 pactl set-sink-volume @DEFAULT_SINK@ "$1"%
41 notify_current_volume
42 ;;
43 up)
44 # expect $2 = % to increase
45 pactl set-sink-volume @DEFAULT_SINK@ +"$2"%
46 notify_current_volume
47 ;;
48 down)
49 pactl set-sink-volume @DEFAULT_SINK@ -"$2"%
50 notify_current_volume
51 ;;
52 *)
53 printf "unknown command\n"
54 exit 1
55 ;;
56esac