mpdmenu 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. all_name='[ALL]'
  3. mode=library
  4. d_artist() {
  5. mpc list artist | sort -f | dmenu -fn Terminus:size=17 -p artist "${dmenu_args[@]}"
  6. }
  7. d_album() {
  8. local artist="$1"
  9. local albums
  10. mapfile -t albums < <(mpc list album artist "$artist")
  11. if (( ${#albums[@]} > 1 )) ; then
  12. {
  13. printf '%s\n' "$all_name"
  14. printf '%s\n' "${albums[@]}" | sort -f
  15. } | dmenu -p album "${dmenu_args[@]}"
  16. else
  17. # We only have one album, so just use that.
  18. printf '%s\n' "${albums[0]}"
  19. fi
  20. }
  21. d_playlist() {
  22. local format="%position% - %title% - %album% - %artist%"
  23. local track
  24. track=$(mpc playlist -f "$format" | dmenu -p track "${dmenu_args[@]}")
  25. printf '%s' "${track%% *}"
  26. }
  27. i=2
  28. for arg do
  29. if [[ $arg == :: ]]; then
  30. dmenu_args=( "${@:$i}" )
  31. break
  32. fi
  33. case "$arg" in
  34. -l) mode=library ;;
  35. -p) mode=playlist ;;
  36. esac
  37. let i++
  38. done
  39. case "$mode" in
  40. library)
  41. artist=$(d_artist)
  42. [[ $artist ]] || exit 1
  43. album=$(d_album "$artist")
  44. [[ $album ]] || exit 2
  45. mpc clear
  46. if [[ $album == "$all_name" ]]; then
  47. mpc find artist "$artist" | sort | mpc add
  48. else
  49. mpc find artist "$artist" album "$album" | sort | mpc add
  50. fi
  51. mpc play >/dev/null 2>&1
  52. ;;
  53. playlist)
  54. mpc play "$(d_playlist)"
  55. ;;
  56. esac