-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmediac
More file actions
executable file
·118 lines (102 loc) · 2.74 KB
/
mediac
File metadata and controls
executable file
·118 lines (102 loc) · 2.74 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env zsh
set -e
((DEBUG)) && set -x
zshexit () {
(($?)) && notify 'Unable to manage media' 'dialog-error'
}
current-mute-state () {
pacmd list-sinks | awk '/\* /{t=1};/^\t*muted:/{if (t==1) print $2; t=0}'
}
volume () {
pacmd list-sinks | awk '/\* /{t=1};/^\t*volume:/{if (t==1) print $5; t=0}'
}
notify () {
notify-send.sh -h string:x-dunst-stack-tag:mediac -p "$@"
}
notify_volume () {
local volume
volume="$(volume)"
case "$(current-mute-state)" in
(no)
case "$volume" in
([3-8][0-9]%) level='medium' ;;
([0-9][0-9][0-9]%);& (9[0-9]%) level='high' ;;
([1-2][0-9]%);& ([1-9]%);& (0%) level='low' ;;
esac
notify "$volume" --icon="audio-volume-$level" --expire-time=600 ;;
(yes) notify 'muted' --icon='audio-volume-muted' --expire-time=600 ;;
esac
}
set-volume () {
case "$1" in
(+*) target_volume="$(( ${$(volume)%%%} + ${${1/+}:-5} ))" ;;
(-*) target_volume="$(( ${$(volume)%%%} - ${${1/-}:-5} ))" ;;
(*) target_volume="${1:-${$(volume)%%%}}" ;;
esac
pacmd set-sink-volume "${sink_index}" $((target_volume * 655))
notify_volume
}
play-pause () {
case "$(playerctl status)" in
(Playing)
playerctl pause
notify --icon media-playback-pause-symbolic \
"Pause"
;;
(Paused)
playerctl play
notify --icon media-playback-start-symbolic \
"Play"
;;
esac
}
next-or-previous () {
case "$(playerctl status)" in
(Playing)
playerctl pause
notify --icon 'media-playback-pause-symbolic' \
"Pause"
;;
(Paused)
playerctl play
notify --icon 'media-playback-start-symbolic' \
"Play"
;;
esac
}
next () {
playerctl 'next'
notify --icon 'media-skip-forward' 'next'
}
previous () {
playerctl 'previous'
notify --icon 'media-skip-backward' 'previous'
}
toggle-mute () {
if [ "$arg2" = 'yes' ] || [ "$arg2" = 'no' ]
then
mute_state="$arg2"
else
mute_state="${${$(current-mute-state)/yes/0}/no/1}"
fi
pacmd set-sink-mute "${sink_index}" "$mute_state"
notify_volume
}
usage () {
cat <<EOF >&2
mediac [next|previous|play-pause|toggle-mute [yes|no]] | [<volume>|[+|-]<delta>]
EOF
}
sink_index="$(pacmd list-sinks | awk '/\*/{print $3}')"
arg="$1"
arg2="$2"
case "$arg" in
(next|previous|play-pause|toggle-mute) "$arg" ;;
(*)
if [ "$arg" = 0 ] || [ $((arg)) -ne 0 ]
then
set-volume "$arg"
else
usage
fi ;;
esac