-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpd-control.bash
More file actions
140 lines (125 loc) · 2.77 KB
/
Copy pathmpd-control.bash
File metadata and controls
140 lines (125 loc) · 2.77 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
icons="$HOME/.config/hypr/icons"
get_volume() {
volume=$(mpc volume | awk '{print $2}' | tr -d '%')
if [[ $volume -eq "0" ]]; then
volume_name="muted"
else
volume_name=$(mpc volume)
fi
}
get_icon() {
if [[ "$volume" -eq "0" ]]; then
icon="$icons/volume-mute.png"
elif [[ ("$volume" -ge "0") && ("$volume" -le "30") ]]; then
icon="$icons/volume-low.png"
elif [[ ("$volume" -ge "30") && ("$volume" -le "60") ]]; then
icon="$icons/volume-mid.png"
elif [[ ("$volume" -ge "60") && ("$volume" -le "100") ]]; then
icon="$icons/volume-high.png"
fi
}
get_song() {
full_song=$(mpc status | awk NR==1 | awk -F ' - ' '{$1=""; print $0}')
echo $full_song
length=${#full_song}
if [[ $length -gt 20 ]]; then
song=$(echo $full_song | awk '{print substr($0, 1, 20),"..."}')
else
song=$full_song
fi
echo $song
}
user_notify() {
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "MPD" "$volume_name"
}
mute() {
mpc volume | awk '{print $2}' | tr -d % > ~/.config/hypr/scripts/.current-volume.md
mpc volume 0
get_volume
get_icon
user_notify
}
unmute() {
volume=$(cat $HOME/.config/hypr/scripts/.current-volume.md)
length=${#volume}
if [[ $length -eq 0 ]]; then
volume=100
fi
mpc volume $volume
get_icon
user_notify
}
fetch_volume() {
echo $(mpc volume)
}
toggle_mute() {
get_volume
if [[ $volume -eq "0" ]]; then
unmute
else
mute
fi
get_volume
user_notify
}
inc_volume() {
mpc volume +5
get_volume
get_icon
user_notify
}
dec_volume() {
mpc volume -5
get_volume
get_icon
user_notify
}
next() {
mpc next > /dev/null
get_song
icon="$icons/next-song.png"
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Now playing: " "$song"
}
previous() {
mpc prev > /dev/null
get_song
icon="$icons/previous-song.png"
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Now playing: " "$song"
}
play-pause() {
mpc toggle > /dev/null
if [[ $(mpc status | awk NR==2 | awk '{print$1}') == "[playing]" ]]; then
get_song
icon="$icons/pause-song.png"
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Now playing: " "$song"
else
icon="$icons/play-song.png"
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "MPD" "Paused"
fi
}
# Execute accordingly
if [[ "$1" == "--get" ]]; then
type="volume"
fetch_volume
elif [[ "$1" == "--inc" ]]; then
type="volume"
inc_volume
elif [[ "$1" == "--dec" ]]; then
type="volume"
dec_volume
elif [[ "$1" == "--toggle-mute" ]]; then
type="volume"
toggle_mute
elif [[ "$1" == "--next" ]]; then
type="song"
next
elif [[ "$1" == "--prev" ]]; then
type="song"
previous
elif [[ "$1" == "--toggle-play" ]]; then
type="song"
play-pause
else
fetch_volume
fi