bin/mp: preserve order of input arguments

This commit is contained in:
xeruf 2021-10-16 11:24:14 +02:00
parent 6f5338edcf
commit b8136717b9
1 changed files with 24 additions and 22 deletions

View File

@ -4,26 +4,28 @@
# env: MUSIC # env: MUSIC
PLAYLISTS="$MUSIC/Playlists" PLAYLISTS="$MUSIC/Playlists"
LINKS="$MUSIC/links" LINKS="$MUSIC/links"
test "$1" = "-q" && quiet=-q && shift if test "$1" = "-r"
test "$1" = "-v" && verbose=-v && shift then shift
test "$1" = "-r" && shift || next=true test "$1" = "-v" && verbose=-v && shift
{ for arg; for arg;
do path="$(test -e "$arg" && realpath "$arg" || do path="$(test -e "$arg" && realpath "$arg" ||
( test -e "$MUSIC/$arg" && realpath "$MUSIC/$arg") || ( test -e "$MUSIC/$arg" && realpath "$MUSIC/$arg") ||
( test -e "$PLAYLISTS/$arg" && realpath "$PLAYLISTS/$arg") )" ( test -e "$PLAYLISTS/$arg" && realpath "$PLAYLISTS/$arg") )"
test -n "$verbose" && echo "Scanning path '$path' from '$arg'" >&2 test -n "$verbose" && echo "Scanning path '$path' from '$arg'" >&2
test -n "$path" || continue test -n "$path" || continue
if file "$path" | grep -i ' playlist' || expr "$path" : ".*\.m3u8\?$" >/dev/null if file "$path" | grep -i ' playlist' || expr "$path" : ".*\.m3u8\?$" >/dev/null
then pushd "$(dirname "$path")" >/dev/null && cat "$path" | xargs --delim='\n' "$0" $verbose -r && popd >/dev/null then pushd "$(dirname "$path")" >/dev/null && cat "$path" | xargs --delim='\n' "$0" $verbose -r && popd >/dev/null
else else
find "$path" -name "*.flac" -o -name "*.mp3" | while read file find "$path" -name "*.flac" -o -name "*.mp3" | while read file
do case "$path" in do case "$path" in
($MUSIC/*) echo "${file/$MUSIC\/}";; ($MUSIC/*) echo "${file/$MUSIC\/}";;
(*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";; (*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";;
esac done esac done
fi fi
done && mpc -q update --wait; } | xargs --delim='\n' mpc insert done
else
if test "$next" test "$1" = "-q" && quiet=-q && shift
then test $(mpc status | wc -l) -gt 1 && mpc $quiet next || mpc $quiet play { "$0" -r "$@" && mpc -q update --wait; } |
xargs --delim='\n' mpc insert
test $(mpc status | wc -l) -gt 1 && mpc $quiet next || mpc $quiet play
fi fi