My build of nnn with minor changes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

mocplay 2.1 KiB

il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env sh
  2. # Description: Appends and optionally plays music in MOC
  3. #
  4. # Notes:
  5. # - if selection is available, plays it, else plays the current file or directory
  6. # - appends tracks and exits is MOC is running, else clears playlist and adds tracks
  7. # - to randomize the order of files appended to the playlist, set SHUFFLE=1
  8. # if you add a directory with many files when SHUFFLE=1 is set, it might take a very long time to finish!
  9. # - max 100 files are added
  10. #
  11. # Shell: POSIX compliant
  12. # Author: Arun Prakash Jana, ath3
  13. IFS="$(printf '\n\r')"
  14. selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
  15. cmd=$(pgrep -x mocp 2>/dev/null)
  16. ret=$cmd
  17. SHUFFLE="${SHUFFLE:-0}"
  18. mocp_add ()
  19. {
  20. if [ "$SHUFFLE" = 1 ]; then
  21. if [ "$resp" = "y" ]; then
  22. arr=$(tr '\0' '\n' < "$selection")
  23. elif [ -n "$1" ]; then
  24. arr="$1"
  25. fi
  26. for entry in $arr
  27. do
  28. if [ -d "$entry" ]; then
  29. arr2=$arr2$(find "$entry" -type f \( ! -iname "*.m3u" ! -iname "*.pls" \))
  30. elif echo "$entry" | grep -qv '\.m3u$\|\.pls$' ; then
  31. arr2=$(printf "%s\n%s" "$entry" "$arr2")
  32. fi
  33. done
  34. echo "$arr2" | shuf -n 100 | xargs -d "\n" mocp -a
  35. else
  36. if [ "$resp" = "y" ]; then
  37. xargs < "$selection" -0 mocp -a
  38. else
  39. mocp -a "$1"
  40. fi
  41. fi
  42. }
  43. if [ ! -s "$selection" ] && [ -z "$1" ]; then
  44. exit
  45. fi
  46. if [ "$2" = "opener" ]; then
  47. :
  48. elif [ -s "$selection" ]; then
  49. printf "Work with selection? Enter 'y' to confirm: "
  50. read -r resp
  51. fi
  52. if [ -z "$ret" ]; then
  53. # mocp not running
  54. mocp -S
  55. else
  56. # mocp running, check if it's playing
  57. state=$(mocp -i | grep "State:" | cut -d' ' -f2)
  58. if [ "$state" = 'PLAY' ]; then
  59. # add to playlist and exit
  60. mocp_add "$1"
  61. # uncomment the line below to show mocp interface after appending
  62. # mocp
  63. exit
  64. fi
  65. fi
  66. # clear selection and play
  67. mocp -c
  68. mocp_add "$1" "$resp"
  69. mocp -p
  70. # uncomment the line below to show mocp interface after appending
  71. # mocp