diff options
Diffstat (limited to 'dot/local')
-rwxr-xr-x | dot/local/bin/lpdf | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/dot/local/bin/lpdf b/dot/local/bin/lpdf index 911be80..41f52c4 100755 --- a/dot/local/bin/lpdf +++ b/dot/local/bin/lpdf | |||
@@ -1,18 +1,44 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | |||
3 | # lpdf -- print with lp to a PDF file; output the filename to stdout | 2 | # lpdf -- print with lp to a PDF file; output the filename to stdout |
4 | 3 | ||
5 | lp "$@" -d PDF | | 4 | move_pdf() |
5 | { | ||
6 | local o f="$1" | ||
7 | o=$f | ||
8 | o=${o##*/} | ||
9 | o=${o%%__*} | ||
10 | o=${o%.txt}.pdf | ||
11 | mv -i -T -- "$f" "$o" | ||
12 | } | ||
13 | |||
14 | run_lp() | ||
15 | { | ||
16 | set -x | ||
17 | lp "$@" -d PDF | ||
18 | } | ||
19 | |||
20 | extract_lp_pdf_filename() | ||
6 | { | 21 | { |
7 | read _ _ _ pdf _ | 22 | read _ _ _ pdf _ |
8 | case "$pdf" in | 23 | case "$pdf" in |
9 | PDF-*) glob=$(printf "~/PDF/*-job_%s.pdf\n" "${pdf#PDF-}") ;; | 24 | PDF-*) glob=$(printf "~/PDF/*-job_%s.pdf\n" "${pdf#PDF-}") ;; |
10 | *) exit 1 ;; | 25 | *) exit 1 ;; |
11 | esac | 26 | esac |
12 | sleep=0.1 | 27 | |
13 | while ! (eval "shopt -s failglob; echo $glob") 2>/dev/null | 28 | sleep=1 |
29 | while true | ||
14 | do | 30 | do |
15 | sleep $sleep | 31 | if f=$(shopt -s failglob; 2>/dev/null eval "echo $glob") |
32 | then | ||
33 | printf "%s\n" "$f" | ||
34 | break | ||
35 | else | ||
36 | sleep $sleep | ||
37 | sleep=$((sleep + 1)) | ||
38 | fi | ||
16 | done | 39 | done |
17 | } | 40 | } |
18 | 41 | ||
42 | set -e | ||
43 | read pdf < <(run_lp "$@" | extract_lp_pdf_filename) | ||
44 | move_pdf "$pdf" | ||