Ctrl-insert in listview
[llpp.git] / llppac
blob712f39590b488a19c109fe8d7bd154524ca97a4a
1 #!/bin/sh
3 set -e
5 CACHEDIR=$HOME/.config/llpp
7 die()
9 echo "$1" >&2
10 exit 1
13 executable_p() {
14 command -v $1 >/dev/null 2>&1
17 trap '! test -z $casp && rm -f $casp' 0
19 test -d $CACHEDIR || die "cache directory $CACHEDIR does not exist"
20 while getopts m: opt; do
21 case "$opt" in
22 m) mime="$OPTARG";;
24 die "usage: $0 [-t mime/type] path";
25 exit 1;;
26 esac
27 done
28 shift $(($OPTIND - 1))
29 test -z "$1" && die "usage $0: path"
31 ft=$(file --mime-type -b "$1")
33 case $ft in
34 application/x-gzip) dc=zcat;;
35 application/x-xz) dc=xzcat;;
36 application/x-bzip2) dc=bzcat;;
37 *) unset dc;;
38 esac
40 test -z $dc || ft=$(file --mime-type -bz "$1")
42 filt='${dc-cat} "$1" |'
44 mime=${mime:-$ft}
45 case $mime in
46 application/postscript) conv='ps2pdf - $casp';;
47 application/pdf) test -z $dc && exec llpp "$1" || conv='cat >$casp';;
48 image/vnd.djvu) conv='djvups - | ps2pdf - $casp';;
49 application/msword) {
50 if executable_p unoconv && test -z $dc; then
51 unset filt
52 conv='unoconv -o $casp "$1"'
53 else
54 conv='antiword -m 8859-1.txt -a a4 - >$casp'
56 };;
57 application/vnd.openxmlformats-officedocument.*) {
58 if executable_p unoconv; then
59 ! test -z $dc && die "can not convert compressed $mime"
60 unset filt
61 conv='unoconv -o $casp "$1"'
62 else
63 die 'unoconv not found'
65 };;
66 image/svg+xml) {
67 executable_p rsvg-convert \
68 && conv='rsvg-convert -f pdf -o $casp' \
69 || conv='inkscape -z -A $casp -'
70 };;
71 image/*) conv='convert - pdf:$casp';;
72 application/x-dvi) {
73 test -z $dc || die "can not handle compressed DVIs"
74 unset filt
75 conv='dvipdf $1 $casp'
76 };;
77 *) die "unhandled file type: $mime";;
78 esac
80 hash=$(md5sum "$1" | cut -f 1 -d\ )
81 casp="$CACHEDIR/$hash"
82 test -e $casp || eval "$filt" "$conv"
84 origin="$1"
85 shift
86 exec llpp -origin "$origin" $casp "$@"