-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprevlpr
executable file
·434 lines (387 loc) · 12.5 KB
/
prevlpr
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#!/bin/bash
# Printer can be specified in file ~/.prevlpr_printer.txt
# converts things to ps, shows them, prints them.
# Obviously, if you prefer psbinding a print then you need psbind in the path. http://freecode.com/projects/psbind
function exitcl {
cd -
l=1
while [ -n "$l" ]; do
sleep 1
l=`lsof 2>/dev/null +d /tmp/$k`
done
rm -f -R /tmp/$k
exit
}
if [ -f ~/.prevlpr_printer.txt ]; then
printer=`cat ~/.prevlpr_printer.txt`
else
printer=""
fi
for j in "$@"
do
for i in *$j*
do
# Bash parameter expansion
veg=${i##*.}
elej=${i%.*}
if [[ "$veg" == "pdf" ]] || [[ "$veg" == "PDF" ]] || [[ "$veg" == "ps" ]] || [[ "$veg" == "PS" ]] || [[ "$veg" == "doc" ]] || [[ "$veg" == "docx" ]] || [[ "$veg" == "rtf" ]] || [[ "$veg" == "ods" ]] || [[ "$veg" == "odt" ]] || [[ "$veg" == "xls" ]] || [[ "$veg" == "xlsx" ]] || [[ "$veg" == "xlsm" ]] || [[ "$veg" == "ppt" ]] || [[ "$veg" == "pptx" ]] || [[ "$veg" == "pps" ]] || [[ "$veg" == "csv" ]] || [[ "$veg" == "txt" ]] || [[ "$veg" == "tex" ]] || [[ "$veg" == "ltx" ]] || [[ "$veg" == "html" ]] || [[ "$veg" == "htm" ]]; then
#k=v3$elej`date +%N`
k=v3$elej`date +%y%m%d_%H%M%S`_`strings /dev/urandom | tr -dc a-z-0-9 | tr -d - | head -c5`
mkdir /tmp/$k
chmod 700 /tmp/$k/
cp "$i" /tmp/$k
catthatfile "/tmp/$k" "$i" &
cd /tmp/$k
# Convert to ps
if [[ "$veg" == "pdf" ]] || [[ "$veg" == "PDF" ]]; then
command -v pdftops > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "I need pdftops but I can't find it."
exitcl
fi
pdftops "$i"
fi
if [[ "$veg" == "doc" ]] || [[ "$veg" == "docx" ]] || [[ "$veg" == "rtf" ]] || [[ "$veg" == "ods" ]] || [[ "$veg" == "odt" ]] || [[ "$veg" == "xls" ]] || [[ "$veg" == "xlsx" ]] || [[ "$veg" == "xlsm" ]] || [[ "$veg" == "ppt" ]] || [[ "$veg" == "pptx" ]] || [[ "$veg" == "pps" ]] || [[ "$veg" == "csv" ]]; then
command -v libreoffice > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "I need libreoffice but I can't find it."
exitcl
fi
command -v pdftops > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "I need pdftops but I can't find it."
exitcl
fi
libreoffice --headless --convert-to pdf "$i"
pdftops "$elej.pdf"
fi
if [[ "$veg" == "txt" ]]; then
command -v a2ps > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "I need a2ps but I can't find it."
exitcl
fi
a2ps -o "$elej.ps" "$i"
fi
if [[ "$veg" == "PS" ]]; then
cp "$i" "$elej.ps"
fi
if [[ "$veg" == "tex" ]] || [[ "$veg" == "ltx" ]]; then
command -v latex > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "I need LaTeX but I can't find it."
exitcl
fi
cd -
cp *.bib /tmp/$k
cp *.png /tmp/$k
cp *.pdf /tmp/$k
cp *.eps /tmp/$k
cp *.epsi /tmp/$k
cp *.ps /tmp/$k
cp *.clo /tmp/$k
cp *.cls /tmp/$k
cp *.bst /tmp/$k
cp *.sty /tmp/$k
cd /tmp/$k
# Do we have solutions?
solutions=0
if grep -q "setbool{solu}{true}" "$i"
then
solutions=1
fi
if grep -q "setbool{solu}{false}" "$i"
then
solutions=1
fi
if grep -q "setbool{fullsolu}{true}" "$i"
then
solutions=2
fi
if grep -q "setbool{fullsolu}{false}" "$i"
then
solutions=2
fi
if [ "$solutions" -eq "1" ]
then
read -p "This file has solutions [s] or no solutions [n] versions. Hit s or n, or else keep the original.
" solnosol
if [ "$solnosol" == "s" ]
then
cat $i |
awk ' BEGIN{
soldone=0
}
{
if ($0=="\%\\setbool{solu}{true}" || $0=="\\setbool{solu}{true}" || $0=="\%\\setbool{solu}{false}" || $0=="\\setbool{solu}{false}") {
if (soldone==0) {
print("\\setbool{solu}{true}");
soldone=1
};
}
else {
print($0)
};
}' > sol_"$i"
mv sol_"$i" "$i"
fi
if [ "$solnosol" == "n" ]
then
cat $i |
awk ' BEGIN{
soldone=0
}
{
if ($0=="\%\\setbool{solu}{true}" || $0=="\\setbool{solu}{true}" || $0=="\%\\setbool{solu}{false}" || $0=="\\setbool{solu}{false}") {
if (soldone==0) {
print("\\setbool{solu}{false}");
soldone=1
};
}
else {
print($0)
};
}' > nosol_"$i"
mv nosol_"$i" "$i"
fi
fi
if [ "$solutions" -eq "2" ]
then
read -p "This file has full solutions [f] or solutions [s] or no solutions [n] versions. Hit f s or n, or else keep the original.
" solnosol
if [ "$solnosol" == "s" ]
then
cat $i |
awk ' BEGIN{
soldone=0
fullsoldone=0
}
{
if ($0=="\%\\setbool{solu}{true}" || $0=="\\setbool{solu}{true}" || $0=="\%\\setbool{solu}{false}" || $0=="\\setbool{solu}{false}") {
if (soldone==0) {
print("\\setbool{solu}{true}");
soldone=1
};
}
else if ($0=="\%\\setbool{fullsolu}{true}" || $0=="\\setbool{fullsolu}{true}" || $0=="\%\\setbool{fullsolu}{false}" || $0=="\\setbool{fullsolu}{false}") {
if (fullsoldone==0) {
print("\\setbool{fullsolu}{false}");
fullsoldone=1
};
}
else {
print($0)
};
}' > sol_"$i"
mv sol_"$i" "$i"
fi
if [ "$solnosol" == "n" ]
then
cat $i |
awk ' BEGIN{
soldone=0
fullsoldone=0
}
{
if ($0=="\%\\setbool{solu}{true}" || $0=="\\setbool{solu}{true}" || $0=="\%\\setbool{solu}{false}" || $0=="\\setbool{solu}{false}") {
if (soldone==0) {
print("\\setbool{solu}{false}");
soldone=1
};
}
else if ($0=="\%\\setbool{fullsolu}{true}" || $0=="\\setbool{fullsolu}{true}" || $0=="\%\\setbool{fullsolu}{false}" || $0=="\\setbool{fullsolu}{false}") {
if (fullsoldone==0) {
print("\\setbool{fullsolu}{false}");
fullsoldone=1
};
}
else {
print($0)
};
}' > nosol_"$i"
mv nosol_"$i" "$i"
fi
if [ "$solnosol" == "f" ]
then
cat $i |
awk ' BEGIN{
soldone=0
fullsoldone=0
}
{
if ($0=="\%\\setbool{solu}{true}" || $0=="\\setbool{solu}{true}" || $0=="\%\\setbool{solu}{false}" || $0=="\\setbool{solu}{false}") {
if (soldone==0) {
print("\\setbool{solu}{true}");
soldone=1
};
}
else if ($0=="\%\\setbool{fullsolu}{true}" || $0=="\\setbool{fullsolu}{true}" || $0=="\%\\setbool{fullsolu}{false}" || $0=="\\setbool{fullsolu}{false}") {
if (fullsoldone==0) {
print("\\setbool{fullsolu}{true}");
fullsoldone=1
};
}
else {
print($0)
};
}' > fullsol_"$i"
mv fullsol_"$i" "$i"
fi
fi
latex -interaction=nonstopmode "$i"
cd -
if [[ -f "$elej".bbl ]]
then
cp "$elej".bbl /tmp/$k
cd /tmp/$k
else
cd /tmp/$k
bibtex "$elej".aux
fi
makeindex "$elej"
latex -interaction=nonstopmode "$i"
latex -interaction=nonstopmode "$i"
latex -interaction=nonstopmode "$i"
dvips "$elej".dvi
fi
if [[ "$veg" == "html" ]] || [[ "$veg" == "html" ]]; then
command -v html2ps > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "I need html2ps but I can't find it."
exitcl
fi
html2ps "$i" > "$elej.ps"
fi
# Show result
gv "$elej.ps" &
read -p "How do you like the ps? o: ok, print it (duplex printer); s: short edge print it (duplex printer); t: two sided print on simple printer; p: psbind it; e: prepare pdf for email printing; f: same w/ even pages upside-down; n: no options to lpr; anything else to forget it.
" tetszik
# If ok:
if [ "$tetszik" == "o" ]; then
if [ "$printer" == "" ]; then
lpr -o sides=two-sided-long-edge "$elej.ps"
echo "Sent $elej.ps to printer."
else
lpr -o sides=two-sided-long-edge -P"$printer" "$elej.ps"
echo "Sent $elej.ps to $printer."
fi
elif [ "$tetszik" == "n" ]; then
if [ "$printer" == "" ]; then
lpr "$elej.ps"
echo "Sent $elej.ps to printer."
else
lpr -P"$printer" "$elej.ps"
echo "Sent $elej.ps to $printer."
fi
elif [ "$tetszik" == "s" ]; then
if [ "$printer" == "" ]; then
lpr -o sides=two-sided-short-edge "$elej.ps"
#https://dvinfo.ifh.de/Printing_with_Cups#I.27m_using_psutils_.28pstops.2Cpsnup.2Cpsbook.29._Even_though_I.27m_using_the_option_.27.27sides.3Dtwo-sided-short-edge.27.27_the_output_was_not_arranged_in_the_correct_order._What_can_I_do.3F
#lp -o document-format=application/bindshort "$elej.ps"
echo "Sent $elej.ps to printer (short edge)."
else
lpr -o sides=two-sided-short-edge -P"$printer" "$elej.ps"
#lp -o document-format=application/bindshort -d"$printer" "$elej.ps"
echo "Sent $elej.ps to $printer (short edge)."
fi
elif [ "$tetszik" == "t" ]; then
if [ "$printer" == "" ]; then
psselect -e -r "$elej.ps" | lpr
echo "Sent the even pages of $elej.ps to printer."
echo "Turn sheets in their plane and refeed, press [enter] when ready."
read
psselect -o "$elej.ps" | lpr
echo "Sent the odd pages of $elej"_"$k.ps to printer."
else
psselect -e -r "$elej.ps" | lpr -P"$printer"
echo "Sent the even pages of $elej.ps to $printer."
echo "Turn sheets in their plane and refeed, press [enter] when ready."
read
psselect -o "$elej.ps" | lpr -P"$printer"
echo "Sent the odd pages of $elej"_"$k.ps to $printer."
fi
elif [ "$tetszik" == "e" ]; then
ps2pdf "$elej.ps" "$elej"_email.pdf
cpcl "$elej"_email.pdf
zathura "$elej"_email.pdf
#evince "$elej"_email.pdf
#xpdf "$elej"_email.pdf
elif [ "$tetszik" == "f" ]; then
ps2pdf "$elej.ps" "$elej"_torot.pdf
pdftk A="$elej"_torot.pdf shuffle Aodd Aevensouth output "$elej"_email.pdf
cpcl "$elej"_email.pdf
zathura "$elej"_email.pdf
#evince "$elej"_email.pdf
#xpdf "$elej"_email.pdf
# If psbind:
elif [ "$tetszik" == "p" ]; then
psbind "$elej.ps" > "$elej"_"$k.ps"
gv "$elej"_"$k.ps" &
read -p "How do you like the psbinded ps? o: ok, print it; s: long edge print it; t: two sided print on simple printer, e: prepare pdf for email printing; f: same w/ even pages upside-down; n: no options to lpr; anything else to forget it.
" tetszikp
if [ "$tetszikp" == "o" ]; then
if [ "$printer" == "" ]; then
lpr -o sides=two-sided-short-edge "$elej"_"$k.ps"
#lp -o document-format=application/bindshort "$elej"_"$k.ps"
echo "Sent $elej"_"$k.ps to printer."
else
lpr -o sides=two-sided-short-edge -P"$printer" "$elej"_"$k.ps"
#lp -o document-format=application/bindshort -d"$printer" "$elej"_"$k.ps"
echo "Sent $elej"_"$k.ps to $printer."
fi
elif [ "$tetszikp" == "n" ]; then
if [ "$printer" == "" ]; then
lpr "$elej"_"$k.ps"
echo "Sent $elej"_"$k.ps to printer."
else
lpr -P"$printer" "$elej"_"$k.ps"
echo "Sent $elej"_"$k.ps to $printer."
fi
elif [ "$tetszikp" == "s" ]; then
if [ "$printer" == "" ]; then
lpr -o sides=two-sided-long-edge "$elej"_"$k.ps"
echo "Sent $elej"_"$k.ps to printer (long edge)."
else
lpr -o sides=two-sided-long-edge -P"$printer" "$elej"_"$k.ps"
echo "Sent $elej"_"$k.ps to $printer (long edge)."
fi
elif [ "$tetszikp" == "t" ]; then
if [ "$printer" == "" ]; then
psselect -e -r "$elej"_"$k.ps" | lpr
echo "Sent the even pages of $elej"_"$k.ps to printer."
echo "Refeed sheets without turning, press [enter] when ready."
read
psselect -o "$elej"_"$k.ps" | lpr
echo "Sent the odd pages of $elej"_"$k.ps to printer."
else
psselect -e -r "$elej"_"$k.ps" | lpr -P"$printer"
echo "Sent the even pages of $elej"_"$k.ps to $printer."
echo "Refeed sheets without turning, press [enter] when ready."
read
psselect -o "$elej"_"$k.ps" | lpr -P"$printer"
echo "Sent the odd pages of $elej"_"$k.ps to $printer."
fi
elif [ "$tetszikp" == "e" ]; then
ps2pdf "$elej"_"$k.ps" "$elej"_email.pdf
cpcl "$elej"_email.pdf
zathura "$elej"_email.pdf
#evince "$elej"_email.pdf
#xpdf "$elej"_email.pdf
elif [ "$tetszikp" == "f" ]; then
ps2pdf "$elej"_"$k.ps" "$elej"_torot.pdf
pdftk A="$elej"_torot.pdf shuffle Aodd Aevensouth output "$elej"_email.pdf
cpcl "$elej"_email.pdf
zathura "$elej"_email.pdf
#evince "$elej"_email.pdf
#xpdf "$elej"_email.pdf
else
echo "Ok, forget it."
fi
# If not nice:
else
echo "Ok, forget it."
fi
exitcl
fi
done
done