added exiftool to show info about fb2 file
[far2l.git] / far2l / bootstrap / view.sh
blobe556dd562541f8f55a2738459c4f2c70f94109db
1 #!/bin/bash
2 # This script used by Viewer to produce F5-toggled 'Processed view' content.
3 # It gets input file as 1st argument, tries to analyze what is it and should
4 # write any filetype-specific information into output file, given in 2nd argument.
5 # Input: $1
6 # Output: $2
8 FILE="$(file "$1")"
10 # Optional per-user script
11 if [ -x ~/.config/far2l/view.sh ]; then
12 . ~/.config/far2l/view.sh
15 echo "$FILE" > "$2"
16 echo >> "$2"
18 if [[ "$FILE" == *" archive data, "* ]] \
19 || [[ "$FILE" == *" compressed data"* ]] \
20 || [[ "$FILE" == *": Debian "*" package"* ]] \
21 || [[ "$FILE" == *": RPM"* ]]; then
22 if command -v exiftool >/dev/null 2>&1; then
23 exiftool "$1" | head -n 40 | head -c 1024 >>"$2" 2>&1
24 echo "" >>"$2" 2>&1
25 else
26 echo "Install <exiftool> to see information" >>"$2" 2>&1
28 echo "------------" >>"$2" 2>&1
29 echo "Processing file as archive with 7z contents listing" >>"$2" 2>&1
30 echo "----bof----" >>"$2" 2>&1
31 if command -v 7z >/dev/null 2>&1; then
32 7z l "$1" >>"$2" 2>&1
33 else
34 echo "Install <p7zip-full> to see information" >>"$2" 2>&1
36 if [[ "$FILE" == *" compressed data"* ]]; then
37 echo "------------" >>"$2" 2>&1
38 echo "Processing file as archive with tar contents listing" >>"$2" 2>&1
39 TAROPTS=""
40 if [[ "$FILE" == *": gzip compressed data"* ]]; then
41 TAROPTS=-z
43 if [[ "$FILE" == *": bzip2 compressed data"* ]]; then
44 TAROPTS=-j
46 if [[ "$FILE" == *": XZ compressed data"* ]]; then
47 TAROPTS=-J
49 if [[ "$FILE" == *": lzma compressed data"* ]]; then
50 TAROPTS=--lzma
52 if [[ "$FILE" == *": lzop compressed data"* ]]; then
53 TAROPTS=--lzop
55 if [[ "$FILE" == *": zstd compressed data"* ]]; then
56 TAROPTS=--zstd
58 if [[ "$(tar --help | grep -e '--full-time' | wc -l)" == "1" ]]; then
59 TAROPTS=$TAROPTS" --full-time"
61 echo "TAROPTS=[ "$TAROPTS" ]" >>"$2" 2>&1
62 echo "------------" >>"$2" 2>&1
63 ELEMENTCOUNT=$( tar -tv $TAROPTS -f "$1" 2>/dev/null | wc -l )
64 echo "tar archive elements count = "$ELEMENTCOUNT >>"$2" 2>&1
65 if [[ $ELEMENTCOUNT -gt 0 ]]; then
66 echo "------------" >>"$2" 2>&1
67 tar -tv $TAROPTS -f "$1" >>"$2" 2>&1
68 echo "------------" >>"$2" 2>&1
69 tar -tv $TAROPTS -f "$1" | \
70 tee >/dev/null \
71 >( CTOTAL=$( wc -l ) ; ( echo $CTOTAL' total' ; echo "----done----" ; ) >>"$2" 2>&1 ) \
72 >( CFOLDERS=$( grep -e '^d' | wc -l ) ; ( echo $CFOLDERS' folders' ) >>"$2" 2>&1 ) \
73 >( CFILES=$( grep -v -e '^d' | wc -l ) ; ( echo $CFILES' files' ) >>"$2" 2>&1 )
76 echo "----eof----" >>"$2" 2>&1
77 exit 0
80 if [[ "$FILE" == *ELF*executable* ]] || [[ "$FILE" == *ELF*object* ]]; then
81 if command -v exiftool >/dev/null 2>&1; then
82 exiftool "$1" | head -n 40 | head -c 1024 >>"$2" 2>&1
83 echo "" >>"$2" 2>&1
84 else
85 echo "Install <exiftool> to see information" >>"$2" 2>&1
87 echo "------------" >>"$2" 2>&1
88 if command -v readelf >/dev/null 2>&1; then
89 readelf -n --version-info --dyn-syms "$1" >>"$2" 2>&1
90 else
91 echo "Install <readelf> utility to see more information" >>"$2" 2>&1
93 echo "----eof----" >>"$2" 2>&1
94 exit 0
97 if [[ "$FILE" == *" image data, "* ]] \
98 || [[ "$FILE" == *"JPEG image"* ]]; then
99 # ??? workaround for bash to get values of variables
100 bash -c "echo ${FOO}" >/dev/null 2>&1
101 TCOLUMNS=$( bash -c "echo ${COLUMNS}" )
102 TLINES=$( bash -c "echo ${LINES}" )
103 TCOLUMNS=$(( ${TCOLUMNS:-80} - 0 ))
104 TLINES=$(( ${TLINES:-25} - 2 ))
105 VCHAFA="no"
106 if command -v chafa >/dev/null 2>&1; then
107 VCHAFA="yes"
108 # chafa -c 16 --color-space=din99d --dither=ordered -w 9 --symbols all --fill all !.! && read -n1 -r -p "$1" >>"$2" 2>&1
109 chafa -c none --symbols -all+stipple+braille+ascii+space+extra --size ${TCOLUMNS}x${TLINES} "$1" >>"$2" 2>&1
110 echo "Image is viewed by chafa in "${TCOLUMNS}"x"${TLINES}" symbols sized area" >>"$2" 2>&1
111 chafa -c 16 --color-space=din99d -w 9 --symbols all --fill all "$1" && read -n1 -r -p "" >>"$2" 2>&1
112 clear
113 else
114 echo "Install <chafa> to see picture" >>"$2" 2>&1
116 VJP2A="no"
117 if [[ "$FILE" == *"JPEG image"* ]] \
118 && [[ "$VCHAFA" == "no" ]]; then
119 if command -v jp2a >/dev/null 2>&1; then
120 VJP2A="yes"
121 # jp2a --colors "$1" >>"$2" 2>&1
122 # jp2a --size=${TCOLUMNS}x${TLINES} "$1" >>"$2" 2>&1
123 # jp2a --height=${TLINES} "$1" >>"$2" 2>&1
124 TCOLUMNS=$(( ${TCOLUMNS:-80} - 1 ))
125 jp2a --width=${TCOLUMNS} "$1" >>"$2" 2>&1
126 echo "Image is viewed by jp2a in "${TCOLUMNS}"x"${TLINES}" symbols sized area" >>"$2" 2>&1
127 jp2a --colors --term-fit "$1" && read -n1 -r -p "" >>"$2" 2>&1
128 clear
129 else
130 echo "Install <jp2a> to see colored picture" >>"$2" 2>&1
133 VASCIIART="no"
134 if [[ "$VCHAFA" == "no" ]] \
135 && [[ "$VJP2A" == "no" ]]; then
136 if command -v asciiart >/dev/null 2>&1; then
137 VASCIIART="yes"
138 # asciiart -c "$1" >>"$2" 2>&1
139 asciiart "$1" >>"$2" 2>&1
140 echo "Image is viewed by asciiart in "${TCOLUMNS}"x"${TLINES}" symbols sized area" >>"$2" 2>&1
141 asciiart --color "$1" && read -n1 -r -p "" >>"$2" 2>&1
142 clear
143 else
144 echo "Install <asciiart> to see picture" >>"$2" 2>&1
147 echo "------------" >>"$2" 2>&1
148 if command -v exiftool >/dev/null 2>&1; then
149 exiftool "$1" | head -n 40 | head -c 1024 >>"$2" 2>&1
150 echo "" >>"$2" 2>&1
151 else
152 echo "Install <exiftool> to see information" >>"$2" 2>&1
154 echo "----eof----" >>"$2" 2>&1
155 exit 0
158 if [[ "$FILE" == *": Audio file"* ]]; then
159 if command -v exiftool >/dev/null 2>&1; then
160 exiftool "$1" >>"$2" 2>&1
161 else
162 echo "Install <exiftool> to see information" >>"$2" 2>&1
164 echo "----eof----" >>"$2" 2>&1
165 exit 0
168 if [[ "$FILE" == *": RIFF"*" data"* ]]; then
169 if command -v exiftool >/dev/null 2>&1; then
170 exiftool "$1" >>"$2" 2>&1
171 else
172 echo "Install <exiftool> to see information" >>"$2" 2>&1
174 echo "----eof----" >>"$2" 2>&1
175 exit 0
178 if [[ "$FILE" == *": BitTorrent file"* ]]; then
179 if command -v exiftool >/dev/null 2>&1; then
180 exiftool "$1" >>"$2" 2>&1
181 else
182 echo "Install <exiftool> to see information" >>"$2" 2>&1
184 echo "----eof----" >>"$2" 2>&1
185 exit 0
188 if [[ "$FILE" == *": HTML document"* ]]; then
189 if command -v exiftool >/dev/null 2>&1; then
190 exiftool "$1" | head -n 40 | head -c 1024 >>"$2" 2>&1
191 echo "" >>"$2" 2>&1
192 else
193 echo "Install <exiftool> to see information" >>"$2" 2>&1
195 echo "------------" >>"$2" 2>&1
196 echo "Processing file as html with pandoc ( formatted as markdown )" >>"$2" 2>&1
197 echo "----bof----" >>"$2" 2>&1
198 if command -v pandoc >/dev/null 2>&1; then
199 pandoc -f html -t markdown "$1" >>"$2" 2>&1
200 else
201 echo "Install <pandoc> to see document" >>"$2" 2>&1
203 echo "----eof----" >>"$2" 2>&1
204 exit 0
207 if [[ "$FILE" == *": OpenDocument Text"* ]]; then
208 if command -v exiftool >/dev/null 2>&1; then
209 exiftool "$1" | head -n 40 | head -c 1024 >>"$2" 2>&1
210 echo "" >>"$2" 2>&1
211 else
212 echo "Install <exiftool> to see information" >>"$2" 2>&1
214 echo "------------" >>"$2" 2>&1
215 echo "Processing file as odt with pandoc ( formatted as markdown )" >>"$2" 2>&1
216 echo "----bof----" >>"$2" 2>&1
217 if command -v pandoc >/dev/null 2>&1; then
218 pandoc -f odt -t markdown "$1" >>"$2" 2>&1
219 else
220 echo "Install <pandoc> to see document" >>"$2" 2>&1
222 echo "----eof----" >>"$2" 2>&1
223 exit 0
226 if [[ "$FILE" == *": EPUB document"* ]]; then
227 if command -v exiftool >/dev/null 2>&1; then
228 exiftool "$1" | head -n 40 | head -c 1024 >>"$2" 2>&1
229 echo "" >>"$2" 2>&1
230 else
231 echo "Install <exiftool> to see information" >>"$2" 2>&1
233 echo "------------" >>"$2" 2>&1
234 echo "Processing file as epub with pandoc ( formatted as markdown )" >>"$2" 2>&1
235 echo "----bof----" >>"$2" 2>&1
236 if command -v pandoc >/dev/null 2>&1; then
237 pandoc -f epub -t markdown "$1" >>"$2" 2>&1
238 else
239 echo "Install <pandoc> to see document" >>"$2" 2>&1
241 echo "----eof----" >>"$2" 2>&1
242 exit 0
245 # if [[ "$FILE" == *" FictionBook2 ebook"* ]]; then
246 if [[ "$FILE" == *": XML 1.0 document, UTF-8 Unicode text, with very long lines"* ]]; then
247 if command -v exiftool >/dev/null 2>&1; then
248 exiftool "$1" | head -n 40 | head -c 1024 >>"$2" 2>&1
249 echo "" >>"$2" 2>&1
250 else
251 echo "Install <exiftool> to see information" >>"$2" 2>&1
253 echo "------------" >>"$2" 2>&1
254 echo "Processing file as fb2 with pandoc ( formatted as markdown )" >>"$2" 2>&1
255 echo "----bof----" >>"$2" 2>&1
256 if command -v pandoc >/dev/null 2>&1; then
257 pandoc -f fb2 -t markdown "$1" >>"$2" 2>&1
258 else
259 echo "Install <pandoc> to see document" >>"$2" 2>&1
261 echo "----eof----" >>"$2" 2>&1
262 exit 0
265 if [[ "$FILE" == *": Microsoft Word 2007+"* ]]; then
266 if command -v pandoc >/dev/null 2>&1; then
267 pandoc "$1" >>"$2" 2>&1
268 else
269 echo "Install <pandoc> to see document" >>"$2" 2>&1
271 echo "----eof----" >>"$2" 2>&1
272 exit 0
275 if [[ "$FILE" == *": Composite Document File"*"Microsoft Office Word"* ]]; then
276 if command -v catdoc >/dev/null 2>&1; then
277 catdoc "$1" >>"$2" 2>&1
278 else
279 echo "Install <catdoc> to see document" >>"$2" 2>&1
281 echo "----eof----" >>"$2" 2>&1
282 exit 0
285 if [[ "$FILE" == *": Composite Document File"*"Microsoft PowerPoint"* ]]; then
286 if command -v catppt >/dev/null 2>&1; then
287 catppt "$1" >>"$2" 2>&1
288 else
289 echo "Install <catppt> to see document" >>"$2" 2>&1
291 echo "----eof----" >>"$2" 2>&1
292 exit 0
295 if [[ "$FILE" == *": PDF document"* ]]; then
296 if command -v pdftotext >/dev/null 2>&1; then
297 pdftotext -enc UTF-8 "$1" "$2" 2>>"$2"
298 else
299 echo "Install <pdftotext> to see document" >>"$2" 2>&1
301 echo "----eof----" >>"$2" 2>&1
302 exit 0
305 if [[ "$FILE" == *": unified diff output"* ]]; then
306 if command -v colordiff >/dev/null 2>&1; then
307 cat "$1" | colordiff --color=yes >>"$2" 2>&1
308 else
309 echo "Install <colordiff> to see colored diff" >>"$2" 2>&1
311 echo "----eof----" >>"$2" 2>&1
312 exit 0
315 if [[ "$FILE" == *": "*" source, "*" text"* ]]; then
316 if command -v ctags >/dev/null 2>&1; then
317 ctags --totals -x -u "$1" >>"$2" 2>&1
318 else
319 echo "Install <ctags> to see source overview" >>"$2" 2>&1
321 echo "----eof----" >>"$2" 2>&1
322 exit 0
325 if [[ "$FILE" == *": ASCII text, with very long lines"* ]] \
326 || [[ "$FILE" == *": UTF-8 Unicode text, with very long lines"* ]]; then
327 head -c 256 "$1" >>"$2" 2>&1
328 echo "" >>"$2" 2>&1
329 echo ............ >>"$2" 2>&1
330 tail -c 256 "$1" >>"$2" 2>&1
331 echo "" >>"$2" 2>&1
332 exit 0
335 if [[ "$FILE" == *": ASCII text"* ]] \
336 || [[ "$FILE" == *": UTF-8 Unicode"* ]]; then
337 head "$1" >>"$2" 2>&1
338 echo ............ >>"$2" 2>&1
339 tail "$1" >>"$2" 2>&1
340 exit 0
343 echo "Hint: use <F5> to switch back to raw file viewer" >>"$2" 2>&1
344 #exit 1