cmus-notify.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. msgId="291049"
  4. if [[ ! $(pidof cmus) ]]; then
  5. message="cmus is not currently running..."
  6. echo "$message"
  7. # dunstify -r "$msgId" "$message"
  8. exit 2
  9. fi
  10. cover-music-generate.sh "$(cmus-remote -Q | awk '$1=="file" {$1="";print substr($0,2)}')" "${1:-200}"
  11. most=$(cmus-remote -Q \
  12. | sed 's/^tag //g' \
  13. | grep "^status\|^album\|^albumartist\|^composer\|^artist\|^title" \
  14. | cut -d' ' -f1- \
  15. | sed 's/ /\t/' \
  16. | column -t -s $'\t')
  17. # >>but also, just in case the tag strings contain tabs, they should be replaced by sed before using the above. "␉" is apparently a unicode symbol meant to represent horizontal tab, but spaces or question marks or whatever would obviously work
  18. # most=$(cmus-remote -Q | awk '$1~/status/||$2~/album|albumartist|composer|artist|title/{gsub(/^tag/,"");printf("%-10s",$1);$1="";print}')
  19. tags_not_present=$(cmus-remote -Q | grep ^file | tr -s '/' '\n' | tail -n3)
  20. position=$(date -d@"$(cmus-remote -Q | awk '$1=="position" {print $2}')" -u +%H:%M:%S)
  21. duration=$(date -d@"$(cmus-remote -Q | awk '$1=="duration" {print $2}')" -u +%H:%M:%S)
  22. vol=$(cmus-remote -Q | awk '$2=="vol_left" {$1=$2="";print substr($0,3)}')
  23. tags="${most}"$'\n'"${position}/${duration}"$'\n'"Volume: ${vol}%"
  24. no_tags="${tags_not_present%.*}"$'\n'"${position}/${duration}"$'\n'"Volume: ${vol}%"
  25. title="cmus-notifier"
  26. if [[ $most == "" ]];then
  27. notify-send -i "/tmp/cover.png" "$title" "$no_tags"
  28. # dunstify -i "/tmp/cover.png" -r "$msgId" "$title" "$no_tags"
  29. else
  30. notify-send -i "/tmp/cover.png" "$title" "$tags"
  31. # dunstify -i "/tmp/cover.png" -r "$msgId" "$title" "$tags"
  32. fi
  33. # set this in cmus
  34. # :set status_display_program=<path-to-the-shell-script>
  35. # or set if from console
  36. # cmus-remote -C set status_display_program=<path-to-the-shell-script>