2024-09-08 20:03:55 +00:00
|
|
|
EXEC_SHELL_PATH=$(command -v bash)
|
|
|
|
|
|
|
|
export THUMBNAIL_DIR="$HOME/.cache/lf/epub"
|
|
|
|
|
2024-03-02 21:22:03 +00:00
|
|
|
set -e
|
|
|
|
|
2024-09-08 20:03:55 +00:00
|
|
|
# Define cleanup function to close file descriptor and remove FIFO file
|
2024-03-02 21:22:03 +00:00
|
|
|
cleanup() {
|
|
|
|
exec 3>&-
|
2024-09-08 20:03:55 +00:00
|
|
|
rm "$FIFO_UEBERZUG"
|
2024-03-02 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2024-09-08 20:03:55 +00:00
|
|
|
# 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
|