nowplay 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. # nowplay - a simple script to get track information from cmus
  3. # Code inspired by content found at http://v3gard.com/2011/01/getting-cmus-to-cooperate-with-conky/
  4. # Copyright ©2017-2023 Jason Trunks
  5. # https://notabug.org/JasKinasis/cmus-scripts
  6. # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  8. # You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  9. # Determine whether cmus is running
  10. if ps -C cmus > /dev/null; then
  11. # Get information about cmus current state
  12. data="$(cmus-remote -Q)"
  13. # Parse the data and determine the status of the player
  14. playStatus=$(echo "$data" | awk '/^status / {gsub("status ", "");print}')
  15. # If not stopped - display the details of the currently playing/paused track
  16. if [[ $playStatus != "stopped" ]]; then
  17. artist=$(echo "$data" | awk '/^tag artist / {gsub("tag artist ", "");print}')
  18. title=$(echo "$data" | awk '/^tag title / {gsub("tag title ", "");print}')
  19. echo "Now $playStatus: $artist - $title";
  20. else # output the status of the player
  21. echo "cmus is $playStatus";
  22. fi
  23. else echo "cmus is not running!"; #output nothing if cmus is not running
  24. fi