5 CACHEDIR
=$HOME/.config
/llpp
13 command -v $1 >/dev
/null
2>&1
16 trap '! test -z $casp && rm -f $casp' 0
18 test -d $CACHEDIR || die
"cache directory $CACHEDIR does not exist"
19 while getopts m
: opt
; do
23 die
"usage: $0 [-m mime/type] path";
27 shift $
(($OPTIND - 1))
28 test -z "$1" && die
"usage $0: path"
30 ft
=$
(file -L --mime-type -b "$1") || die
"$ft"
33 application
/x-gzip
) dc=zcat
;;
34 application
/x-xz
) dc=xzcat
;;
35 application
/x-bzip2
) dc=bzcat
;;
39 test -z $dc || ft
=$
(file -L --mime-type -bz "$1") || die
"$ft"
41 filt
='${dc-cat} "$1" |'
45 application
/postscript
) conv
='ps2pdf - $casp';;
46 application
/pdf
) test -z $dc && exec llpp
"$@" || conv
='cat >$casp';;
47 image
/vnd.djvu
) conv
='djvups - | ps2pdf - $casp';;
49 ! test -z $dc && die
"can not convert compressed $mime"
51 conv
='prince "$1" -o $casp'
54 if executable_p unoconv
&& test -z $dc; then
56 conv
='unoconv -o $casp "$1"'
58 conv
='antiword -m 8859-1.txt -a a4 - >$casp'
61 application
/vnd.openxmlformats-officedocument.
*) {
62 ! test -z $dc && die
"can not convert compressed $mime"
64 conv
='unoconv -o $casp "$1"'
67 executable_p rsvg-convert \
68 && conv
='rsvg-convert -f pdf -o $casp' \
69 || conv
='inkscape -z -A $casp -'
71 image
/*) conv
='convert - pdf:$casp';;
73 ! test -z $dc && die
"can not convert compressed $mime"
75 conv
='dvipdf $1 $casp'
77 *) die
"unhandled file type: $mime";;
80 hash=$
(md5sum "$1") || die
"$hash"
81 casp
="$CACHEDIR/${hash%% *}"
82 test -e $casp ||
eval "$filt" "$conv"
84 exec llpp
-origin "$@" $casp