#!/usr/bin/env sh if [ -z "$1" ]; then exit 1; fi basename="$(echo "$1" | sed 's/\.[^\/.]*$//')" wait_pdf() { sleep 5 # Some start delay while true; do if ! pgrep -x "zathura" >/dev/null; then rm -f "$basename".pdf exit 0 fi done } case "$1" in *.tex | *.m[dse] | *.[rR]md | *.mom | *.[0-9]) compile "$1" && preview "$basename".pdf >/dev/null 2>&1 && wait_pdf & ;; *.html) setsid -f "$BROWSER" "$basename".html >/dev/null 2>&1 ;; *.sent) setsid -f sent "$1" >/dev/null 2>&1 ;; *) setsid -f xdg-open "$1" >/dev/null 2>&1 ;; esac