pianobarctl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.1
  6. # This is the FIFO that is used to control pianobar
  7. # It must exist before running pianobar in order for remote control to work
  8. PIANOBARCTL=~/.config/pianobar/ctl
  9. # Control Functions
  10. NEXT="n"
  11. PLAYPAUSE="p"
  12. LOVE="+"
  13. BAN="-"
  14. set -e
  15. usage() {
  16. echo "$(basename $0) $VERSION - by Phillip Warner"
  17. echo "Usage:"
  18. echo " $0 [OPTION]"
  19. echo "Only one parameter can be used at a time."
  20. echo "The script's parameters are:"
  21. echo " -h, --help Help"
  22. echo " -n, --next Play Next"
  23. echo " -p, --pause Play / Pause"
  24. echo " -x, --play Play / Pause"
  25. echo " -l, --love Love Song"
  26. echo " -b, --ban Ban Song"
  27. echo
  28. echo "Current pianobar PIDs (euid=$(id -u)):"
  29. pgrep -u $(id -u) pianobar$
  30. }
  31. # Make sure the FIFO exists
  32. if ! [ -p $PIANOBARCTL ]
  33. then
  34. echo "ERROR. FIFO $PIANOBARCTL does not exist. Try running mkfifo $PIANOBARCTL and then restarting pianobar first. Aborting..."
  35. exit 1
  36. fi
  37. # Make sure pianobar is running and that there is no more than one arg
  38. if ! (pgrep -u $(id -u) pianobar$ &> /dev/null) || [ $2 ]
  39. then
  40. usage
  41. elif [ $1 ]
  42. then
  43. case $1 in
  44. -h|--help ) usage
  45. ;;
  46. -n|--next ) echo -n $NEXT > $PIANOBARCTL
  47. ;;
  48. -p|--pause ) echo -n $PLAYPAUSE > $PIANOBARCTL
  49. ;;
  50. -x|--play ) echo -n $PLAYPAUSE > $PIANOBARCTL
  51. ;;
  52. -l|--love ) echo -n $LOVE > $PIANOBARCTL
  53. ;;
  54. -b|--ban ) echo -n $BAN > $PIANOBARCTL
  55. ;;
  56. * ) usage
  57. ;;
  58. esac
  59. else
  60. usage
  61. fi
  62. exit