-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpdmenu
executable file
·74 lines (59 loc) · 1.43 KB
/
mpdmenu
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
#!/bin/bash
declare all_name='[ALL]'
declare mode='library'
dmenu() {
command dmenu -i -l 10 -fn 'Fantasque Sans Mono' "$@"
}
d_artist() {
mpc list artist | sort -f | dmenu -p artist "${dmenu_args[@]}"
}
d_album() {
local artist="$1"
local albums
mapfile -t albums < <(mpc list album artist "$artist")
if (( ${#albums[@]} > 1 )) ; then
{
printf '%s\n' "$all_name"
printf '%s\n' "${albums[@]}" | sort -f
} | dmenu -p album "${dmenu_args[@]}"
else
# We only have one album, so just use that.
printf '%s\n' "${albums[0]}"
fi
}
d_playlist() {
local format="%position% - %title% - %album% - %artist%"
local track
track=$(mpc playlist -f "$format" | dmenu -p track "${dmenu_args[@]}")
printf '%s' "${track%% *}"
}
i=2
for arg; do
if [[ $arg == :: ]]; then
dmenu_args=( "${@:$i}" )
break
fi
case "$arg" in
-l) mode=library ;;
-p) mode=playlist ;;
esac
(( i++ ))
done
case "$mode" in
library)
artist=$(d_artist)
[[ $artist ]] || exit 1
album=$(d_album "$artist")
[[ $album ]] || exit 2
mpc clear
if [[ $album == "$all_name" ]]; then
mpc findadd artist "$artist"
else
mpc findadd artist "$artist" album "$album"
fi
mpc play >/dev/null 2>&1
;;
playlist)
mpc play "$(d_playlist)"
;;
esac