-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpv-last
More file actions
executable file
·55 lines (44 loc) · 1.03 KB
/
Copy pathmpv-last
File metadata and controls
executable file
·55 lines (44 loc) · 1.03 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
#!/usr/bin/env bash
# wk-prompt setup
# shellcheck disable=SC1091
source wk-prompt
# shellcheck disable=SC2034
wk_keywords=("+write")
# shellcheck disable=SC2034
wk_preprocessor_cmds=(
":delay 0"
":menu-width 0"
)
build_wks_description() {
_wks_desc="${1##*/}"
}
# Last played playlist
savefile="${XDG_CONFIG_HOME:-$HOME/.config}/mpv/playlists/last.m3u"
declare -a lastplayed
selection=
set_last_played() {
readarray -t lastplayed < <(tac "$savefile")
}
assert_last_played() {
[[ "${#lastplayed[@]}" -gt 0 ]] && return 0
notify-send "${0##*/}" "Nothing in '${savefile##*/}' playlist!"
exit 1
}
get_selection() {
selection="$(wk_prompt "${lastplayed[@]}")"
}
play_selection() {
if [[ -n "$selection" ]]; then
perl -i -ne 'BEGIN { $s = shift } print unless $_ eq "$s\n"' "$selection" "$savefile"
mpv --script-opts=mpv-save-enabled=yes "$selection"
else
echo "No selection!"
fi
}
main() {
set_last_played
assert_last_played
get_selection
play_selection
}
main "$@"