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 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 5 ans
il y a 5 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #
  10. # Shell: POSIX compliant
  11. # Author: Arun Prakash Jana, ath3
  12. IFS="$(printf '\n\r')"
  13. selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
  14. cmd=$(pgrep -x mocp 2>/dev/null)
  15. ret=$cmd
  16. SHUFFLE=0
  17. mocp_add ()
  18. {
  19. if [ $SHUFFLE = 1 ]; then
  20. if [ "$resp" = "y" ]; then
  21. arr=$(tr '\0' '\n' < "$selection")
  22. elif [ -n "$1" ]; then
  23. arr="$1"
  24. fi
  25. for entry in $arr
  26. do
  27. if [ -d "$entry" ]; then
  28. arr2=$arr2$(find "$entry" -type f)
  29. else
  30. arr2=$(printf "%s\n%s" "$entry" "$arr2")
  31. fi
  32. done
  33. arr2=$(echo "$arr2" | awk 'BEGIN{srand();}{print rand()"\t"$0}' | sort -k1 -n | cut -f2-)
  34. for entry in $arr2
  35. do
  36. if [ -f "$entry" ] && echo "$entry" | grep -qv '\.m3u$\|\.pls$' ; then
  37. mocp -a "$entry"
  38. fi
  39. done
  40. else
  41. if [ "$resp" = "y" ]; then
  42. xargs < "$selection" -0 mocp -a
  43. else
  44. mocp -a "$1"
  45. fi
  46. fi
  47. }
  48. if [ ! -s "$selection" ] && [ -z "$1" ]; then
  49. exit
  50. fi
  51. if [ "$2" = "opener" ]; then
  52. :
  53. elif [ -s "$selection" ]; then
  54. printf "Work with selection? Enter 'y' to confirm: "
  55. read -r resp
  56. fi
  57. if [ -z "$ret" ]; then
  58. # mocp not running
  59. mocp -S
  60. else
  61. # mocp running, check if it's playing
  62. state=$(mocp -i | grep "State:" | cut -d' ' -f2)
  63. if [ "$state" = 'PLAY' ]; then
  64. # add to playlist and exit
  65. mocp_add "$1"
  66. # uncomment the line below to show mocp interface after appending
  67. # mocp
  68. exit
  69. fi
  70. fi
  71. # clear selection and play
  72. mocp -c
  73. mocp_add "$1" "$resp"
  74. mocp -p
  75. # uncomment the line below to show mocp interface after appending
  76. # mocp