aboutsummaryrefslogtreecommitdiff
path: root/.scripts/preview
blob: 099eb1b511e7b296e76ddcf01003438603a2015a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/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