modern_lisp-machine/misc/scripts/preview.sh

47 lines
1.2 KiB
Bash
Executable File

EXEC_SHELL_PATH=$(command -v bash)
export THUMBNAIL_DIR="$HOME/.cache/lf/epub"
set -e
# Define cleanup function to close file descriptor and remove FIFO file
cleanup() {
exec 3>&-
rm "$FIFO_UEBERZUG"
}
# Check if running over SSH and exit if true
[[ -n $SSH_CLIENT || -n $SSH_TTY ]] && exit 0
# Create necessary directories
[[ ! -d $HOME/.cache/lf ]] && mkdir -p "$HOME/.cache/lf"
export FIFO_UEBERZUG="$HOME/.cache/lf/ueberzug-$$"
mkfifo "$FIFO_UEBERZUG"
# Start ueberzugpp in background
ueberzugpp layer -s <"$FIFO_UEBERZUG" -p json &
exec 3>"$FIFO_UEBERZUG"
trap cleanup EXIT
case "$1" in
*.epub)
EPUB_FILE="$1"
THUMBNAIL_DIR="$HOME/.cache/lf/epub"
mkdir -p "$THUMBNAIL_DIR"
THUMBNAIL_PATH="${THUMBNAIL_DIR}/${EPUB_FILE%.epub}.png"
# Check if the thumbnail exists, if not, generate it
if [[ ! -f $THUMBNAIL_PATH ]]; then
$HOME/.config/lf/epub_thumbnailer.sh "$EPUB_FILE" 256
fi
# Open the generated thumbnail with nsxiv
nsxiv "$THUMBNAIL_DIR" &
# just a workaround, will fix to display the file instead of the
# whole folder
;;
*)
exit 0
;;
esac