My build of nnn with minor changes
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

90 linhas
2.1 KiB

  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 [ -s "$selection" ]; then
  52. printf "Work with selection? Enter 'y' to confirm: "
  53. read -r resp
  54. fi
  55. if [ -z "$ret" ]; then
  56. # mocp not running
  57. mocp -S
  58. else
  59. # mocp running, check if it's playing
  60. state=$(mocp -i | grep "State:" | cut -d' ' -f2)
  61. if [ "$state" = 'PLAY' ]; then
  62. # add to playlist and exit
  63. mocp_add "$1"
  64. # uncomment the line below to show mocp interface after appending
  65. # mocp
  66. exit
  67. fi
  68. fi
  69. # clear selection and play
  70. mocp -c
  71. mocp_add "$1" "$resp"
  72. mocp -p
  73. # uncomment the line below to show mocp interface after appending
  74. # mocp