From b8136717b97613388445c37971ffb66aa88a94c4 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sat, 16 Oct 2021 11:24:14 +0200 Subject: [PATCH] bin/mp: preserve order of input arguments --- .local/bin/scripts/mp | 46 ++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/.local/bin/scripts/mp b/.local/bin/scripts/mp index d6a5d69..b6c4a48 100755 --- a/.local/bin/scripts/mp +++ b/.local/bin/scripts/mp @@ -4,26 +4,28 @@ # 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" || - ( test -e "$MUSIC/$arg" && realpath "$MUSIC/$arg") || - ( test -e "$PLAYLISTS/$arg" && realpath "$PLAYLISTS/$arg") )" - test -n "$verbose" && echo "Scanning path '$path' from '$arg'" >&2 - test -n "$path" || continue - 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 - else - find "$path" -name "*.flac" -o -name "*.mp3" | while read file - do case "$path" in - ($MUSIC/*) echo "${file/$MUSIC\/}";; - (*) 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 +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 + test -n "$path" || continue + 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 + else + find "$path" -name "*.flac" -o -name "*.mp3" | while read file + do case "$path" in + ($MUSIC/*) echo "${file/$MUSIC\/}";; + (*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";; + esac done + fi + 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