3 # Description: Appends and optionally plays music in MOC
6 # - if selection is available, plays it, else plays the current file or directory
7 # - appends tracks and exits is MOC is running, else clears playlist and adds tracks
8 # - to let mocp shuffle tracks, set SHUFFLE=1
10 # Shell: POSIX compliant
11 # Authors: 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)
18 SHUFFLE="${SHUFFLE:-0}"
22 if [ "$SHUFFLE" = 1 ]; then
23 if [ "$resp" = "y" ]; then
24 arr=$(tr '\0' '\n' < "$selection")
25 elif [ -n "$1" ]; then
31 if [ -d "$entry" ]; then
32 arr2=$arr2$(find "$entry" -type f \( ! -iname "*.m3u" ! -iname "*.pls" \))
33 elif echo "$entry" | grep -qv '\.m3u$\|\.pls$' ; then
34 arr2=$(printf "%s\n%s" "$entry" "$arr2")
39 echo "$arr2" | xargs -d "\n" mocp -a
41 if [ "$resp" = "y" ]; then
42 xargs < "$selection" -0 mocp -a
49 if [ ! -s "$selection" ] && [ -z "$1" ]; then
53 if [ "$2" = "opener" ]; then
55 elif [ -s "$selection" ]; then
56 printf "Work with selection? Enter 'y' to confirm: "
60 if [ -z "$ret" ]; then
64 # mocp running, check if it's playing
65 state=$(mocp -i | grep "State:" | cut -d' ' -f2)
67 if [ "$state" = 'PLAY' ]; then
68 # add to playlist and exit
71 # uncomment the line below to show mocp interface after appending
78 # clear selection and play
83 # uncomment the line below to show mocp interface after appending
87 if [ "$resp" = "y" ] && [ -p "$NNN_PIPE" ]; then
88 printf "-" > "$NNN_PIPE"