-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintfile
More file actions
93 lines (86 loc) · 1.55 KB
/
printfile
File metadata and controls
93 lines (86 loc) · 1.55 KB
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
#!/bin/bash
#
# Script to make CLI printing easy.
if [ -z $1 ] ; then
echo "no file specified"
exit 1
elif [ ! -e $1 ]; then
echo 'file "'$1'" does not exist'
exit 1
elif [ ! -f $1 ] ; then
echo '"'$1'" is not a valid file'
exit 1
fi
echo '
printfile: script to make CLI printing easy
'
echo 'available printers:'
lpstat -a | cut -d ' ' -f 1 > ~/log
sed '/./=' ~/log | sed '/./N; s/\n/ /' # put the line number at the beginning of every line
read -p 'enter selection [1-3] > '
if [[ ! $REPLY =~ ^[1-3]$ ]]; then
echo "invalid entry" >&2
exit 1
fi
printer=`sed -n ${REPLY}p log | awk '{print $NF}'` # parse selection and keeps only the printer name
rm ~/log
echo
read -p 'copies > '
if [[ $REPLY =~ ^-?[0-9]+$ ]]; then
copies=$REPLY
else
echo 'copies must be a number'
exit 1
fi
echo '
media size [default a4]:
1 a4
2 letter
3 legal'
read -p 'enter selection [1-3] > '
case $REPLY in
1)
media_size='a4'
;;
2)
media_size='letter'
;;
3)
media_size='legal'
;;
'')
media_size='a4'
;;
*)
echo "invalid entry" >&2
exit 1
;;
esac
echo '
orientation [default two-sided-long-edge]:
1 one-sided
2 two-sided-long-edge
3 two-sided-short-edge'
read -p 'enter selection [1-3] > '
case $REPLY in
1)
orientation='one-sided'
;;
2)
orientation='two-sided-long-edge'
;;
3)
orientation='two-sided-short-edge'
;;
'')
orientation='two-sided-long-edge'
;;
*)
echo "invalid entry" >&2
exit 1
;;
esac
echo '
printing "'$1'"...'
#DEBUG echo $printer $copies $media_size $orientation
lp -d $printer -n $copies -o media=$media_size -o sides=$orientation $1