summaryrefslogtreecommitdiff
path: root/audio/pianobar/pianobarctl
blob: 619ff0c5a074b33676ed6f7c4ea3bb4e5bad0ed1 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh

# pianobarctl
# This script uses a specified named pipe (FIFO) to control pianobar.
# Written by Phillip Warner

VERSION=0.2
# - Updated for new play and "stop" (pause only) controls 
#   added to pianobar starting at version 2013.05.19
# - Added quit option

# This is the FIFO that is used to control pianobar
# It must exist before running pianobar in order for remote control to work
PIANOBARCTL=~/.config/pianobar/ctl

# Control Functions
NEXT="n"
PLAYPAUSE="p"
PLAY="P"
PAUSE="S"
LOVE="+"
BAN="-"
QUIT="q"

set -e

usage() {
	echo "$(basename $0) $VERSION - by Phillip Warner"
        echo "Usage:"
        echo "  $0 [OPTION]"
	echo "Only one parameter can be used at a time."
        echo "The script's parameters are:"
        echo "  -h, --help		Help"
	echo "  -n, --next		Play Next"
	echo "  -p, --pause		Toggle Play / Pause"
	echo "  -x, --play		Play"
	echo "  -v, --stop		Pause"
	echo "  -l, --love		Love Song"
	echo "  -b, --ban		Ban Song"
	echo "  -q, --quit		Quit Program"
	echo
	echo "Current pianobar PIDs (euid=$(id -u)):"
	pgrep -u $(id -u) pianobar$
}

# Make sure the FIFO exists
if ! [ -p $PIANOBARCTL ]
then
	echo "ERROR.  FIFO $PIANOBARCTL does not exist.  Try running mkfifo $PIANOBARCTL and then restarting pianobar first.  Aborting..."
	exit 1
fi

# Make sure pianobar is running and that there is no more than one arg
if ! (pgrep -u $(id -u) pianobar$ &> /dev/null) || [ $2 ]
then
	usage
elif [ $1 ]
then
   case $1 in
      -h|--help ) usage
	;;
      -n|--next ) echo -n $NEXT > $PIANOBARCTL
	;;
      -p|--pause ) echo -n $PLAYPAUSE > $PIANOBARCTL
	;;
      -x|--play ) echo -n $PLAY > $PIANOBARCTL
	;;
      -v|--stop ) echo -n $PAUSE > $PIANOBARCTL
	;;
      -l|--love ) echo -n $LOVE > $PIANOBARCTL
	;;
      -b|--ban ) echo -n $BAN > $PIANOBARCTL
	;;
      -q|--quit ) echo -n $QUIT > $PIANOBARCTL
	;;
      * ) usage
        ;;
   esac
else
	usage
fi

exit