Skip to content

Instantly share code, notes, and snippets.

@prodisDown
Last active June 16, 2023 12:58
Show Gist options
  • Save prodisDown/a9a15d0afbe7ea32ae87bb9dce22e5eb to your computer and use it in GitHub Desktop.
Save prodisDown/a9a15d0afbe7ea32ae87bb9dce22e5eb to your computer and use it in GitHub Desktop.
mpv shell script. Prepends first arg on each line of stdin, then launches mpv with resulting playlist. Uses neat trick with file descriptors and unlinked files.
#!/bin/sh
trap 'printf "(exit) mpv-from\n" >&2' EXIT
usage () {
printf '(usage) mpv-from <basepath> [mpv-args]\n'
}
test $# -ge 1 || {
printf '(error) not enough arguments\n' >&2
usage >&2
exit 127
}
_basepath="$1" ; shift
_pipe="$(mktemp)" \
&& exec 3<>"$_pipe" \
|| {
_ec=$?
printf '(error) can\047t open file descriptor\n' >&2
exit $_ec
}
rm "$_pipe"
awk -v _base="$_basepath" '{print _base $0}' >&3
printf '(info) exec mpv\n' >&2
# can't use fd:// because of bug that prepends 'fd://' to files in playlist if there is no protocol ('file://' protocol not helping)
exec mpv --playlist=- "$@" <&3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment