diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-11-13 14:06:34 +0100 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-11-13 14:06:34 +0100 |
commit | 5bf92dab61950c35afc6266a2ef85056cdeb14ea (patch) | |
tree | 85cd7761812af70f01992538f75f8959687c55ba /bin/extra/append2mpv | |
parent | 09e3e0945dd31005f10d7cc18ccd5b38fdb58f97 (diff) | |
parent | b386965b95808a0ad78e6c1dedaefac4693aaad5 (diff) |
Merge branch 'main' of debuc.com:dotfiles
Diffstat (limited to 'bin/extra/append2mpv')
-rwxr-xr-x | bin/extra/append2mpv | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/extra/append2mpv b/bin/extra/append2mpv new file mode 100755 index 0000000..28c3916 --- /dev/null +++ b/bin/extra/append2mpv @@ -0,0 +1,30 @@ +#!/bin/sh +IPC="/tmp/mpvsocket" + +die () { >&2 printf '%s\n' "$@"; exit 1; } +append_to_mpv() +{ + file="$(readlink -f "$1")" + if [ ! -r "$file" ] + then + >&2 printf '%s\n' "'$file' not found" + return + fi + + echo '{ "command": ["loadfile", "'"$file"'", "append"] }' | + socat - "$IPC" +} + +[ -S "$IPC" ] || die "$IPC is not a socket or doesn't exist" +which socat > /dev/null || exit 1 + + +if [ -t 0 ] +then + append_to_mpv "$1" +else + while read -r file + do + append_to_mpv "$file" + done +fi |