aboutsummaryrefslogtreecommitdiff
path: root/config/i3blocks/scripts/mpd
blob: 113f6e8655bd7f05b9507136592cadc873204cf1 (plain)
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
#!/bin/bash
HOME="192.168.0.217"
HOST=""

# Let's be sneaky and verify that we are on relevant network before we try to ping
if ip a | grep -q 'inet 192.168.0.' && \
		ping -c 1 -w 1 "$HOME" >/dev/null 2>&1; then
	# TODO check that mpd is running?
	HOST="-h $HOME"
fi

# Handle remote volume
if [ "$BLOCK_INSTANCE" = "remote" ]; then
	[ -n "$HOST" ] || exit 0
	case "$BLOCK_BUTTON" in
		1)
			mpc $HOST volume 40 >/dev/null
			;;
		3)
			mpc $HOST volume 0 >/dev/null
			;;
		4)
			mpc $HOST volume +2 >/dev/null
			;;
		5)
			mpc $HOST volume -2 >/dev/null
			;;
	esac

	echo "♫ $(mpc $HOST volume | sed 's/volume: //')"
	exit 0
fi

# Handle user input
case "$BLOCK_BUTTON" in
	1)
		mpc $HOST toggle >/dev/null
		;;
	2)
		mpc $HOST stop >/dev/null
		;;
	3)
		# TODO this doesn't work with host
		nohup urxvt -title "Music player daemon client" -hold -e ncmpcpp 2>&1 >/dev/null &
		;;
	4)
		mpc $HOST prev >/dev/null
		;;
	5)
		mpc $HOST next >/dev/null
		;;
esac

STATUS="$(mpc $HOST status)"
if echo "$STATUS" | grep -qE "(playing|paused)"; then
	echo `mpc $HOST -f "♫ %artist%, %album%, %title%" status | head -1`
	echo
	if echo "$STATUS" | grep -q playing; then
		echo "#00ff00"
	elif echo "$STATUS" | grep -q paused; then
		echo "#ffff00"
	fi
else
	echo "♫"
fi