My build of nnn with minor changes
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

86 rindas
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. # - 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