aboutsummaryrefslogtreecommitdiff
path: root/bin/print_unicode.sh
blob: 24815a0d5ad9aec63d74f63774cd8ca331b8ab04 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

## print_unicode.sh
## By Amanda Hickman https://gist.github.com/amandabee/cf7faad0a6f2afc485ee
## Using https://github.com/baruchel/txt2pdf to print emails to PDF with unicode support. 

pdir="$HOME/.neomutt/tmp" 
open_pdf=qpdfview 
scriptloc="python3 $HOME/.neomutt/bin/text2pdf.py"

# check to make sure that we're looking for txt2pdf in the right place 
if ! command -v python3 $scriptloc  >/dev/null; then
    echo "Is $scriptloc installed?"
    exit 1
fi
	
# create temp dir if it does not exist
if [ ! -d "$pdir" ]; then
    mkdir -p "$pdir" 2>/dev/null
    if [ $? -ne 0 ]; then
        echo "Unable to make directory '$pdir'" 1>&2
        exit 2
    fi
fi

# dump stdin to a tempfile
tmptxt="`mktemp $pdir/mutt_XXXXXXX.txt`"
cat >> $tmptxt

tmpfile="`mktemp $pdir/mutt_XXXXXXXX.pdf`" 

# Actually write the text into a PDF. 
$scriptloc --quiet -o $tmpfile $tmptxt
$open_pdf $tmpfile >/dev/null 2>&1 &
sleep 1
rm $tmpfile
rm $tmptxt