My dotfiles. Period.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/dash
  2. getpos() {
  3. #
  4. # Get track position
  5. #
  6. local h
  7. local m
  8. local s
  9. s=$(qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.PositionGet)
  10. s=$((s/1000))
  11. h=$((s/3600))
  12. s=$((s%3600))
  13. m=$((s/60))
  14. s=$((s%60))
  15. case $h in
  16. 0) printf '%d:%02d' $m $s ;;
  17. *) printf '%d:%02d:%02d' $h $m $s ;;
  18. esac
  19. }
  20. mktext() {
  21. #
  22. # Compose info text from DBus
  23. #
  24. local artist
  25. local year
  26. local album
  27. local tracknumber
  28. local title
  29. local sigil
  30. local sigilcolor
  31. local value
  32. local key
  33. local color_attr
  34. local cache
  35. cache=$(mktemp -t cstatus.GetMetadata.XXXXXXXX)
  36. qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.GetMetadata >"$cache"
  37. case $(qdbus org.mpris.clementine /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus) in
  38. Stopped) sigil=""; sigilcolor= ;;
  39. Playing) sigil=""; sigilcolor=green ;;
  40. Paused) sigil=""; sigilcolor=gray;;
  41. *) sigil=""; sigilcolor=red ;;
  42. esac
  43. test -n "$sigilcolor" && color_attr=" color='$sigilcolor'"
  44. while read -r line; do
  45. key=${line%%:*}
  46. value=${line#$key: }
  47. case $key in
  48. artist) artist=$value ;;
  49. year) year=$value ;;
  50. album) album=$value ;;
  51. tracknumber) tracknumber=$value ;;
  52. title) title=$value ;;
  53. esac
  54. done <"$cache"
  55. printf "%s [%d %s]: %02d %s (%s) <span%s>%s</span>" \
  56. "$artist" "$year" "$album" "$tracknumber" "$title" \
  57. "$(getpos)" \
  58. "$color_attr" "$sigil"
  59. rm "$cache"
  60. }
  61. main() {
  62. local head=true
  63. echo '{"version":1}'
  64. echo "["
  65. while true; do
  66. $head || echo -n ","
  67. head=false
  68. echo -n '[{'
  69. echo -n '"markup":"pango",'
  70. echo -n '"full_text":"'"$(mktext)"'"'
  71. echo -n '}]'
  72. echo
  73. sleep 1
  74. done
  75. }
  76. main