mirror of
https://github.com/jarun/nnn.git
synced 2024-11-19 01:19:14 +00:00
Merge pull request #297 from ath3/mocplay-shuffle
Add shuffle to mocplay
This commit is contained in:
commit
3cc0cf5f0a
|
@ -5,40 +5,68 @@
|
||||||
# Notes:
|
# Notes:
|
||||||
# - if selection is available, plays it, else plays the current file or directory
|
# - if selection is available, plays it, else plays the current file or directory
|
||||||
# - appends tracks and exits is MOC is running, else clears playlist and adds tracks
|
# - appends tracks and exits is MOC is running, else clears playlist and adds tracks
|
||||||
|
# - to randomize the order of files appended to the playlist, set SHUFFLE=1
|
||||||
|
# if you add a directory with many files when SHUFFLE=1 is set, it might take a very long time to finish!
|
||||||
#
|
#
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Author: Arun Prakash Jana
|
# Author: Arun Prakash Jana, ath3
|
||||||
|
|
||||||
|
IFS="$(printf '\n\r')"
|
||||||
selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
|
selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
|
||||||
cmd=$(pgrep -x mocp 2>/dev/null)
|
cmd=$(pgrep -x mocp 2>/dev/null)
|
||||||
ret=$cmd
|
ret=$cmd
|
||||||
|
|
||||||
|
SHUFFLE=0
|
||||||
|
|
||||||
|
mocp_add() {
|
||||||
|
if [ $SHUFFLE = 1 ]; then
|
||||||
if [ -s "$selection" ]; then
|
if [ -s "$selection" ]; then
|
||||||
# try selection first
|
arr=$(tr '\0' '\n' < "$selection")
|
||||||
if [ -z "$ret" ]; then
|
elif [ -n "$1" ]; then
|
||||||
# mocp not running
|
arr="$1"
|
||||||
mocp -S
|
|
||||||
|
|
||||||
# clear selection and play
|
|
||||||
cat "$selection" | xargs -0 mocp -acp
|
|
||||||
else
|
|
||||||
# mocp running, just append
|
|
||||||
cat "$selection" | xargs -0 mocp -a
|
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# ensure a file/dir is passed
|
|
||||||
if ! [ -z "$1" ]; then
|
|
||||||
if [ -z "$ret" ]; then
|
|
||||||
# mocp not running
|
|
||||||
mocp -S
|
|
||||||
|
|
||||||
# clear selection and play
|
for entry in $arr
|
||||||
mocp -acp "$1"
|
do
|
||||||
|
if [ -d "$entry" ]; then
|
||||||
|
arr2=$arr2$(find "$entry" -type f)
|
||||||
|
else
|
||||||
|
arr2=$(printf "%s\n%s" "$entry" "$arr2")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
arr2=$(echo "$arr2" | awk 'BEGIN{srand();}{print rand()"\t"$0}' | sort -k1 -n | cut -f2-)
|
||||||
|
for entry in $arr2
|
||||||
|
do
|
||||||
|
if [ -f "$entry" ] && [ "$(echo "$entry" | grep -v '\.m3u$\|\.pls$')" ]; then
|
||||||
|
mocp -a "$entry"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
else
|
||||||
|
if [ -s "$selection" ]; then
|
||||||
|
xargs < "$selection" -0 mocp -a
|
||||||
else
|
else
|
||||||
# mocp running, just append
|
|
||||||
mocp -a "$1"
|
mocp -a "$1"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ ! -s "$selection" ] && [ -z "$1" ]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$ret" ]; then
|
||||||
|
# mocp not running
|
||||||
|
mocp -S
|
||||||
|
|
||||||
|
# clear selection and play
|
||||||
|
mocp -c
|
||||||
|
mocp_add "$1"
|
||||||
|
mocp -p
|
||||||
|
else
|
||||||
|
# mocp running, just append
|
||||||
|
mocp_add "$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# uncomment the line below to show mocp interface after appending
|
# uncomment the line below to show mocp interface after appending
|
||||||
|
|
Loading…
Reference in a new issue