2022-05-26 01:48:27 +02:00
|
|
|
fifo_open() {
|
|
|
|
# https://unix.stackexchange.com/a/522940/183147
|
|
|
|
dd oflag=nonblock conv=notrunc,nocreat count=0 of="$1" \
|
|
|
|
>/dev/null 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_fifo() {
|
|
|
|
exit_code="${2:-127}"
|
|
|
|
fifo="$(printf '/tmp/ctpvfifo.%s' "${1:-$id}")"
|
|
|
|
[ -e "$fifo" ] || exit "$exit_code"
|
|
|
|
fifo_open "$fifo" || exit "$exit_code"
|
2022-05-25 23:57:50 +02:00
|
|
|
}
|
|
|
|
|
2022-05-22 09:55:04 +02:00
|
|
|
exists() {
|
|
|
|
command -v "$1" > /dev/null
|
|
|
|
}
|
2022-05-25 23:57:50 +02:00
|
|
|
|
2022-05-26 01:48:27 +02:00
|
|
|
check_exist() {
|
|
|
|
[ $? = 127 ] && exit 127
|
|
|
|
}
|
|
|
|
|
|
|
|
cache() {
|
2022-05-28 16:07:59 +02:00
|
|
|
cache_f="$("$ctpv" -C "$f")"
|
2022-05-26 01:48:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
show_image() {
|
|
|
|
path="$(printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g')"
|
|
|
|
printf '{ "action": "add", "identifier": "preview", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' "$x" "$y" "$w" "$h" "$path" > "$fifo"
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_and_show_image() {
|
|
|
|
setup_fifo
|
|
|
|
cache || "$@" || check_exist
|
|
|
|
show_image "$cache_f"
|
|
|
|
exit 1
|
2022-05-25 23:57:50 +02:00
|
|
|
}
|