-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpls
executable file
·68 lines (55 loc) · 1.83 KB
/
mpls
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
#!/usr/bin/env fish
# mpls - list tracks in mpd's current playlist.
# unlike 'mpc playlist' it includes the index of each item by default, and shows an indicator next to the current track.
# includes a -c or --context argument to only show the tracks near the currently-playing one.
# usage:
# mpls [-h/--help] [-c/--context[=N]]
# examples:
#
# list the whole playlist:
# mpls
#
# show the current song and 10 before and after it:
# mpls -c
#
# show the current song and the 20 before and after it:
# mpls -c 20
# settings:
# text to show in front of the current track
set prepend '▶ '
# code:
set -- script "$(path basename (status filename))"
argparse -n "$script" 'h/help' 'c/context=?!_validate_int --min 1' -- $argv
if set -q _flag_h
echo "$script - list tracks in mpd's current playlist."
echo "Usage: $script [arguments] [number]"
echo
echo " -h/--help - Print help and exit."
echo " -c/--context - Only show N items of \"context\" around the current track (default: 10). Without this argument, the full playlist is listed."
exit
end
set mpc (mpc --format='%position% - ')
set formatargs "--format=%position% - %artist% - %title%"
if test -n "$_flag_c"
set num "$_flag_c"
else
set num 10
end
if test (count $argv) -gt 0; and string match -qr '^\d+$' $argv[1] # FIX: this method of setting context is deprecated.
set num $argv[1]
end
if test (count $mpc) -gt 1 # MPD is playing.
set mpc (echo $mpc[1])
if set -q _flag_c
mpc $formatargs playlist | grep -i -A $num -B $num "^$mpc" | sed "s/^$mpc/$prepend$mpc/"
else
mpc $formatargs playlist | sed "s/^$mpc/$prepend$mpc/"
end
else # MPD is not playing any track.
if set -q _flag_c
echo "$script: MPD is not playing, so there is no playlist context." >&2
exit 1
else
mpc $formatargs playlist
end
end