-
Notifications
You must be signed in to change notification settings - Fork 0
/
music
executable file
·57 lines (48 loc) · 1.06 KB
/
music
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
#!/usr/bin/env bash
set -euo pipefail
TMUX_SESSION=music
if tmux has-session -t music 2> /dev/null; then
tmux attach-session -t music
exit
fi
read -rd '' process << 'EOF' || true
cleanup() {
killall ncmpcpp
killall mopidy
sleep 2
tmux kill-session -t "${TMUX_SESSION}"
}
trap cleanup TERM
trap '' INT
until mpc random on > /dev/null 2>&1; do
sleep 1
done
clear
mpc consume on
while true; do
read -rp 'mpc> ' cmd
case "$cmd" in
exit)
cleanup
;;
p)
mpc toggle
;;
pauseafter)
sleep "$(mpc | awk -F"[ /:]" '/playing/ {print 60*($8-$6)+$9-$7}')"
mpc pause
;;
*)
mpc $cmd
;;
esac
done
EOF
tmux new-session -d -s "${TMUX_SESSION}" 'mopidy'
tmux split-window -t "${TMUX_SESSION}:1.1" -v -p 75 "while true; do ncmpcpp; done"
tmux split-window -t "${TMUX_SESSION}:1.1" -h -p 60 "$process"
if [ -z "${TMUX+x}" ]; then
tmux attach-session -t "${TMUX_SESSION}:1.2"
else
echo "Started in background."
fi