-
Notifications
You must be signed in to change notification settings - Fork 0
/
replaylast
executable file
·37 lines (26 loc) · 1.24 KB
/
replaylast
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
#!/bin/bash
# nb: the swp file that editscript relies on is provided by nano
. ~/.config/mpd-local.conf
on='✅'
editscript(){
local scriptpath script path swp; scriptpath=$(realpath "$0" 2>/dev/null); script="${scriptpath##*/}"; path="${scriptpath%/*}"; swp="$path/.$script.swp"
[[ ! -e "$swp" ]] && printf "\n\n%s\n\n" "$swp" && (/usr/bin/nano "$scriptpath") && exit
printf "\n%s is already being edited.\n%s exists; try fg or look in another window.\n" "$scriptpath" "$swp"; exit ;}
pause(){ read -rp "$*" < /dev/tty; }
[[ "$1" == @(edit|e|-e) ]] && editscript
. <(mpd-current.py)
lastsong="$(grep -E 'player: (played|skipped)' /var/log/mpd/mpd.log|tail -1)"
lastsong="${lastsong%\"*}"; lastsong="${lastsong#*\"}"
printf \\n\\nlastsong\:\ %s\\n\\n "$lastsong"
#to get from mpc
#song_position="$(\mpc -q -h "$mpdpass@$mpdhost" current -f %position%)"
if [[ "$consume" = "$on" ]]; then
\mpc -q -h "$mpdpass@$mpdhost" random off
\mpc -q -h "$mpdpass@$mpdhost" insert "$lastsong"
\mpc -q -h "$mpdpass@$mpdhost" move $(( song_position+1 )) "$song_position"
\mpc -q -h "$mpdpass@$mpdhost" prev
else
\mpc -q -h "$mpdpass@$mpdhost" prev
fi
#reset random to initial state:
if [[ "$random" = "$on" ]]; then \mpc -q -h "$mpdpass@$mpdhost" random on; fi