1.1 KiB
1.1 KiB
Watch PDF
I use this script for working on Typst project, see here
So when using typst to create documents, it is fine to have something watching the typst changes, and reload the file with evince, so you constantly see the changes to the pdf.
I use this bash script with inotifywait, make a bash script and add it to path Use watch-pdf /path/to/file.pdf okay?
#!/usr/bin/env bash
set -euo pipefail
[[ -z "$1" ]] && { echo "ERROR: No PDF filename provided"; exit 1; }
PDF_PATH="$1"
if [[ ! -f "${PDF_PATH}" ]]; then
echo "ERROR: ${PDF_PATH} is not a regular file"
exit 1
fi
command -v evince &> /dev/null || { echo "❌ evince not found. Install: sudo apt-get install evince"; exit 1; }
echo "=== Reload Watcher Started ==="
echo "Monitoring ${PDF_PATH} for writes…"
while IFS= read -r change_file; do
[[ "${change_file}" == "${PDF_PATH}" ]] || continue
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ${PDF_PATH} modified → opening evince"
evince "${PDF_PATH}" &
done < <(inotifywait -mr --format '%w%f' -e close_write "${PDF_PATH}")
echo "Watcher stopped."