-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfls
executable file
·158 lines (147 loc) · 3.51 KB
/
pdfls
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
#!/bin/bash
version=0.1.2
############################################################################
## ##
## pdfls: A shell-script to view a batch of pdf files consecutively ##
## ##
## Author: Pavel Loskot, [email protected] ##
## ##
## Usage: "textblocks -help" ##
## ##
## License: GNU/GPL version 2 or later. No other warranty. ##
## ##
## Configuration file may appear in future versions. ##
## ##
## Developed and tested with GNU bash version 5.2.15 ##
## ##
############################################################################
trap "echo :exiting;exit 1" SIGINT SIGTERM
set -e
export LC_CTYPE="en_US.utf8"
this="${0/#*\/}"
if [[ "$#" == "0" || "$1" == @(-h|--help) ]]; then
echo "
$this - a shell script for block/batch viewing pdf files
Usage: pdfls [params] files|[-f|--file <filename>]
Parameters:
-h, --help show this help and quit
-q, --quiet do not display any messages
-i, --info show output of pdfinfo
-k, --keypress interactive mode with keys enabled
-f, --file <filename> read file names from this file
Keys: (interactive mode)
h:help t:target s:size c:copy m:move n:next o:nOte q:quit
"
exit 0
fi
quiet=no
pinfo=no
keypress=no
fromfile=no
fname=
files=
while [[ $# > 0 ]]; do
case $1 in
-q|--quiet)
quiet=yes
keypress=no
;;
-i|--info)
pinfo=yes
quiet=yes
keypress=yes
;;
-k|--keypress)
keypress=yes
quiet=no
;;
-f|--file)
fromfile=yes
shift
fname=$1
break
;;
-*)
echo uknown parameter "$par"
exit 1
;;
*)
files=$(ls -1U "$@" | grep ".pdf\|.PDF\|.epub")
break
;;
esac
shift
done
if [[ "$fromfile" == "yes" ]]; then
files=$(cat $fname)
fi
n=$(ls -1 $files 2</dev/null | wc -l)
c=0
target=$HOME
for f in $files; do
if [[ ! -f "$f" ]]; then
echo "$f" does not exist, skipping
let n=n-1
continue
fi
let c=c+1
if [[ "$quiet" == "no" ]]; then
echo [$c/$n]:$f
echo -n "${f%.*}" | \xclip -selection clipboard
fi
if [[ "$pinfo" == "yes" ]]; then
clear
pdfinfo $f
echo
echo [$c/$n]:$f
fi
if [[ "$keypress" == "yes" ]]; then
/usr/bin/okular $f 2> /dev/null &
p=$!
while : ; do
read -n 1 -s a
case "$a" in
h)
echo "t:target s:size c:copy m:move n:next o:nOte q:quit"
;;
t)
read -e -p "t=" -i "$target" t
target=${t}
;;
s)
ls -lh $f
;;
m)
read -e -p "mv % " -i "\$t" a
cmd=$(echo "mv $f $a" | sed "s|\$t|$target|")
$cmd
break
;;
c)
read -e -p "cp % " -i "\$t" a
cmd=$(echo "cp $f $a" | sed "s|\$t|$target|")
$cmd
break
;;
o)
f1=${f%.*}.note
touch $f1
vim $f1
break
;;
q)
exit 1
;;
n)
break
;;
*)
break
;;
esac
done
kill -13 $p
else
/usr/bin/okular $f 2> /dev/null
fi
done