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 1.8 KiB

il y a 5 ans
il y a 5 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. if [ $SHUFFLE = 1 ]; then
  19. if [ -s "$selection" ]; then
  20. arr=$(tr '\0' '\n' < "$selection")
  21. elif [ -n "$1" ]; then
  22. arr="$1"
  23. fi
  24. for entry in $arr
  25. do
  26. if [ -d "$entry" ]; then
  27. arr2=$arr2$(find "$entry" -type f)
  28. else
  29. arr2=$(printf "%s\n%s" "$entry" "$arr2")
  30. fi
  31. done
  32. arr2=$(echo "$arr2" | awk 'BEGIN{srand();}{print rand()"\t"$0}' | sort -k1 -n | cut -f2-)
  33. for entry in $arr2
  34. do
  35. if [ -f "$entry" ] && [ "$(echo "$entry" | grep -v '\.m3u$\|\.pls$')" ]; then
  36. mocp -a "$entry"
  37. fi
  38. done
  39. else
  40. if [ -s "$selection" ]; then
  41. xargs < "$selection" -0 mocp -a
  42. else
  43. mocp -a "$1"
  44. fi
  45. fi
  46. }
  47. if [ ! -s "$selection" ] && [ -z "$1" ]; then
  48. exit
  49. fi
  50. if [ -z "$ret" ]; then
  51. # mocp not running
  52. mocp -S
  53. # clear selection and play
  54. mocp -c
  55. mocp_add "$1"
  56. mocp -p
  57. else
  58. # mocp running, just append
  59. mocp_add "$1"
  60. fi
  61. # uncomment the line below to show mocp interface after appending
  62. # mocp