pianobarctl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. # pianobarctl
  3. # This script uses a specified named pipe (FIFO) to control pianobar.
  4. # Written by Phillip Warner
  5. VERSION=0.2
  6. # - Updated for new play and "stop" (pause only) controls
  7. # added to pianobar starting at version 2013.05.19
  8. # - Added quit option
  9. # This is the FIFO that is used to control pianobar
  10. # It must exist before running pianobar in order for remote control to work
  11. PIANOBARCTL=~/.config/pianobar/ctl
  12. # Control Functions
  13. NEXT="n"
  14. PLAYPAUSE="p"
  15. PLAY="P"
  16. PAUSE="S"
  17. LOVE="+"
  18. BAN="-"
  19. QUIT="q"
  20. set -e
  21. usage() {
  22. echo "$(basename $0) $VERSION - by Phillip Warner"
  23. echo "Usage:"
  24. echo " $0 [OPTION]"
  25. echo "Only one parameter can be used at a time."
  26. echo "The script's parameters are:"
  27. echo " -h, --help Help"
  28. echo " -n, --next Play Next"
  29. echo " -p, --pause Toggle Play / Pause"
  30. echo " -x, --play Play"
  31. echo " -v, --stop Pause"
  32. echo " -l, --love Love Song"
  33. echo " -b, --ban Ban Song"
  34. echo " -q, --quit Quit Program"
  35. echo
  36. echo "Current pianobar PIDs (euid=$(id -u)):"
  37. pgrep -u $(id -u) pianobar$
  38. }
  39. # Make sure the FIFO exists
  40. if ! [ -p $PIANOBARCTL ]
  41. then
  42. echo "ERROR. FIFO $PIANOBARCTL does not exist. Try running mkfifo $PIANOBARCTL and then restarting pianobar first. Aborting..."
  43. exit 1
  44. fi
  45. # Make sure pianobar is running and that there is no more than one arg
  46. if ! (pgrep -u $(id -u) pianobar$ &> /dev/null) || [ $2 ]
  47. then
  48. usage
  49. elif [ $1 ]
  50. then
  51. case $1 in
  52. -h|--help ) usage
  53. ;;
  54. -n|--next ) echo -n $NEXT > $PIANOBARCTL
  55. ;;
  56. -p|--pause ) echo -n $PLAYPAUSE > $PIANOBARCTL
  57. ;;
  58. -x|--play ) echo -n $PLAY > $PIANOBARCTL
  59. ;;
  60. -v|--stop ) echo -n $PAUSE > $PIANOBARCTL
  61. ;;
  62. -l|--love ) echo -n $LOVE > $PIANOBARCTL
  63. ;;
  64. -b|--ban ) echo -n $BAN > $PIANOBARCTL
  65. ;;
  66. -q|--quit ) echo -n $QUIT > $PIANOBARCTL
  67. ;;
  68. * ) usage
  69. ;;
  70. esac
  71. else
  72. usage
  73. fi
  74. exit