This repository has been archived by the owner on Mar 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprint-svg
executable file
·101 lines (87 loc) · 2.95 KB
/
print-svg
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
#!/bin/bash
set -eu -o pipefail
safe_source () { [[ ! -z ${1:-} ]] && source $1; _dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"; _sdir=$(dirname "$(readlink -f "$0")"); }; safe_source
# end of bash boilerplate
show_help(){
cat <<HELP
$(basename $0) [options] file.svg
Prints the file.svg from default printer via lpr.
Options:
--test : flip all objects vertically to generate test output
--remote [target] : print over remote machine via ssh. Default target is "pcb".
--list : list available printers
HELP
exit
}
die(){
echo "$1"
show_help
exit 1
}
# Parse command line arguments
# ---------------------------
# Initialize parameters
list_printers=false
test_mode=false
remote_printer=
# ---------------------------
args=("$@")
_count=1
while :; do
key="${1:-}"
case $key in
-h|-\?|--help|'')
show_help # Display a usage synopsis.
exit
;;
# --------------------------------------------------------
--list) shift
list_printers=true
;;
--test) shift
test_mode=true
;;
--remote) shift
remote_printer=${1:-pcb}
;;
# --------------------------------------------------------
-*) # Handle unrecognized options
echo
echo "Unknown option: $1"
show_help
exit 1
;;
*) # Generate the positional arguments: $_arg1, $_arg2, ...
[[ ! -z ${1:-} ]] && declare _arg$((_count++))="$1" && shift
esac
[[ -z ${1:-} ]] && break
done; set -- "${args[@]}"
# use $_arg1 in place of $1, $_arg2 in place of $2 and so on, "$@" is intact
if [[ $list_printers = true ]]; then
echo "----------------------------------------------------------------------"
lpstat -p -d | cut -d '.' -f 1
exit
echo "----------------------------------------------------------------------"
fi
echo "----------------------------------------------------------------------"
echo "Using $(lpstat -p -d | grep default | cut -d: -f2)"
echo "----------------------------------------------------------------------"
[[ -z $_arg1 ]] && die "Filename is required."
filename="$_arg1"
if [[ $test_mode = true ]]; then
# this opens inkscape and performs necessary operations.
# you are responsible for printing.
inkscape -g \
--verb=EditSelectAll \
--verb=ObjectFlipHorizontally \
--verb=EditDeselect \
--verb=FilePrint \
--verb EditUndo \
--verb FileQuit \
"$filename"
elif [[ $remote_printer != "" ]]; then
inkscape --without-gui --export-pdf=/dev/stdout "$filename" | ssh $remote_printer lpr
else
# use default printer
inkscape --without-gui --export-pdf=/dev/stdout "$filename" | lpr
fi