Configuration file for dwm-bar on macbook air
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #!/bin/sh
  2. # A dwm_bar function that shows the current artist, track, duration, and status from Spotify using playerctl
  3. # Joe Standring <git@joestandring.com>
  4. # GNU GPLv3
  5. # Dependencies: spotify/spotifyd, playerctl
  6. # NOTE: The official spotify client does not provide the track position or shuffle status through playerctl. This does work through spotifyd however.
  7. dwm_spotify () {
  8. if ps -C spotify > /dev/null; then
  9. PLAYER="spotify"
  10. elif ps -C spotifyd > /dev/null; then
  11. PLAYER="spotifyd"
  12. fi
  13. if [ "$PLAYER" = "spotify" ] || [ "$PLAYER" = "spotifyd" ]; then
  14. ARTIST=$(playerctl metadata artist)
  15. TRACK=$(playerctl metadata title)
  16. POSITION=$(playerctl position | sed 's/..\{6\}$//')
  17. DURATION=$(playerctl metadata mpris:length | sed 's/.\{6\}$//')
  18. STATUS=$(playerctl status)
  19. SHUFFLE=$(playerctl shuffle)
  20. if [ "$IDENTIFIER" = "unicode" ]; then
  21. if [ "$STATUS" = "Playing" ]; then
  22. STATUS="▶"
  23. else
  24. STATUS="⏸"
  25. fi
  26. if [ "$SHUFFLE" = "On" ]; then
  27. SHUFFLE=" 🔀"
  28. else
  29. SHUFFLE=""
  30. fi
  31. else
  32. if [ "$STATUS" = "Playing" ]; then
  33. STATUS="PLA"
  34. else
  35. STATUS="PAU"
  36. fi
  37. if [ "$SHUFFLE" = "On" ]; then
  38. SHUFFLE=" S"
  39. else
  40. SHUFFLE=""
  41. fi
  42. fi
  43. if [ "$PLAYER" = "spotify" ]; then
  44. printf "%s%s %s - %s " "$SEP1" "$STATUS" "$ARTIST" "$TRACK"
  45. printf "%0d:%02d" $((DURATION%3600/60)) $((DURATION%60))
  46. printf "%s\n" "$SEP2"
  47. else
  48. printf "%s%s %s - %s " "$SEP1" "$STATUS" "$ARTIST" "$TRACK"
  49. printf "%0d:%02d/" $((POSITION%3600/60)) $((POSITION%60))
  50. printf "%0d:%02d" $((DURATION%3600/60)) $((DURATION%60))
  51. printf "%s%s\n" "$SHUFFLE" "$SEP2"
  52. fi
  53. fi
  54. }
  55. dwm_spotify