-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmpdmenu.sh
executable file
·98 lines (79 loc) · 1.88 KB
/
mpdmenu.sh
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
#!/bin/bash
MPC="mpc --quiet -p ${1:-6600}"
# max height for vertical menu
height=20
DMENU() {
# Vertical menu if $3 is given
echo -e "$1" | dmenu -i -b -p "$2" ${3:+"-l" "$3"}
}
get_playlist() {
$MPC -f "%position% - %artist% - %album% - %title%" playlist
}
select_from() {
DMENU "$1" "Select $2" $height
}
add() {
all="[ALL]"
local artist=$(select_from "$($MPC list Artist)\n$all" "artist")
if [ "$artist" = "$all" ]; then
$MPC listall | $MPC add;
elif [ -n "$artist" ]; then
local albums=$($MPC list Album Artist "$artist")
local album=$(select_from "$albums\n$all" "album")
if [ "$album" = "$all" ]; then
$MPC findadd Artist "$artist"
elif [ -n "$album" ]; then
local songs=$($MPC list Title Album "$album")
local song=$(select_from "$songs\n$all" "song")
if [ "$song" = "$all" ]; then
$MPC findadd Album "$album"
elif [ -n "$song" ]; then
$MPC findadd Title "$song"
fi
fi
fi
}
remove() {
local playlist=$(get_playlist)
local song=$(select_from "$playlist" "song")
[ -n "$song" ] && $MPC del "${song%%\ *}"
}
jump() {
local playlist=$(get_playlist)
local song=$(select_from "$playlist" "song")
[ -n "$song" ] && $MPC play "${song%%\ *}"
}
toggle(){
$MPC toggle
}
play(){
$MPC play
}
pause(){
$MPC pause
}
stop(){
$MPC stop
}
next(){
$MPC next
}
prev(){
$MPC prev
}
while true; do
action=$(DMENU "Clear\nAdd\nRemove\nJump\nToggle\nPlay\nPause\nStop\nNext\nPrev" "Do you want to")
case $action in
Clear) $MPC clear;;
Add) add;;
Remove) remove;;
Jump) jump;;
Pause) pause;;
Toggle) toggle;;
Play) play;;
Stop) stop;;
Next) next;;
Prev) prev;;
"") exit 0;;
esac
done