#!/bin/sh set -eu QUEUE="$HOME/archive/vid/queue.txt" NEXT="$(head -n1 "$QUEUE")" if [ -z "$NEXT" ]; then echo 'Queue is empty!' else if mpv "$NEXT" 2>/dev/null | tail -n1 | grep '^Exiting\.\.\. (End of file)$'; then echo "Finished playing '$NEXT', getting next on the queue." >&2 NEW_QUEUE="$(mktemp)" tail -n+2 "$QUEUE" > "$NEW_QUEUE" mv "$NEW_QUEUE" "$QUEUE" viddq else echo "Quit playing '$NEXT' without finishing, not removing it from the queue." fi fi