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,11 +4,11 @@
# env: MUSIC
PLAYLISTS="$MUSIC/Playlists"
LINKS="$MUSIC/links"
test "$1" = "-q" && quiet=-q && shift
test "$1" = "-v" && verbose=-v && shift
test "$1" = "-r" && shift || next=true
{ for arg;
do path="$(test -e "$arg" && realpath "$arg" ||
if test "$1" = "-r"
then shift
test "$1" = "-v" && verbose=-v && shift
for arg;
do path="$(test -e "$arg" && realpath "$arg" ||
( test -e "$MUSIC/$arg" && realpath "$MUSIC/$arg") ||
( test -e "$PLAYLISTS/$arg" && realpath "$PLAYLISTS/$arg") )"
test -n "$verbose" && echo "Scanning path '$path' from '$arg'" >&2
@ -22,8 +22,10 @@ do path="$(test -e "$arg" && realpath "$arg" ||
(*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";;
esac done
fi
done && mpc -q update --wait; } | xargs --delim='\n' mpc insert
if test "$next"
then test $(mpc status | wc -l) -gt 1 && mpc $quiet next || mpc $quiet play
done
else
test "$1" = "-q" && quiet=-q && shift
{ "$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