My build of nnn with minor changes
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

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