aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/bin/print (renamed from src/bin/duplex)42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/bin/duplex b/src/bin/print
index 12b254e8..ce069417 100755
--- a/src/bin/duplex
+++ b/src/bin/print
@@ -4,8 +4,8 @@ set -eu
usage() {
cat <<-'EOF'
Usage:
- duplex [-q QUALITY] [FILE...]
- duplex -h
+ print [-d] [-q QUALITY] [FILE...]
+ print -h
EOF
}
@@ -13,6 +13,7 @@ help() {
cat <<-'EOF'
Options:
+ -d print duplex/double-sided
-q QUALITY choose the print quality, either:
low, medium (default) or high.
-h, --help show this message
@@ -20,13 +21,13 @@ help() {
Examples:
Print the given PostScript file with default quality:
- duplex f1.ps
+ print f1.ps
Print multiple PDF files with high quality:
- duplex -q high *.pdf
+ print -q high *.pdf
- Print the file from STDIN:
- cat f2.ps | duplex
+ Print the file from STDIN, double-sided:
+ print -d < f2.ps
EOF
}
@@ -48,14 +49,15 @@ main() {
elif file -b in-tmp | grep -q PDF; then
cp in-tmp in.pdf
else
- printf "Don't know how to duplex print input file:\n" >&2
- file in-tmp >&2
- printf '\nGive me either a PostScript or PDF file instead.\n' >&2
- exit 2
+ enscript -o- in-tmp | ps2pdf - in.pdf
fi
- FULL="$(n_pages in.pdf)"
- if [ "$FULL" = '1' ]; then
+ if [ -z "$DUPLEX" ]; then
+ lp in.pdf
+ return
+ fi
+
+ if [ "$(n_pages in.pdf)" = '1' ]; then
lp in.pdf
return
fi
@@ -93,8 +95,12 @@ for flag in "$@"; do
done
lpoptions -o PrintQuality=standard
-while getopts 'hq:' flag; do
+DUPLEX=
+while getopts 'dq:h' flag; do
case "$flag" in
+ d)
+ DUPLEX=1
+ ;;
q)
case "$OPTARG" in
low)
@@ -125,16 +131,16 @@ while getopts 'hq:' flag; do
done
shift $((OPTIND - 1))
-OLDDIR="$PWD"
-cd "$(mkdtemp)" #FIXME
+NEWDIR="$(mkdtemp)"
if [ -z "${1:-}" ]; then
+ cd "$NEWDIR"
cat - > in-tmp
main
else
for f in "$@"; do
- # ABS="$(echo "$(cd "$(dirname "$f")"; pwd -P)/$(basename "$f")")"
- # echo "$ABS"
- cp "$OLDDIR/$(basename "$f")" in-tmp
+ cp "$f" "$NEWDIR"/in-tmp
+ cd "$NEWDIR"
main
+ cd - > /dev/null
done
fi