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