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.
10 # Optional per-user script
11 if [ -x ~
/.config
/far2l
/view.sh
]; then
12 . ~
/.config
/far2l
/view.sh
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
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
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
40 if [[ "$FILE" == *": gzip compressed data"* ]]; then
43 if [[ "$FILE" == *": bzip2 compressed data"* ]]; then
46 if [[ "$FILE" == *": XZ compressed data"* ]]; then
49 if [[ "$FILE" == *": lzma compressed data"* ]]; then
52 if [[ "$FILE" == *": lzop compressed data"* ]]; then
55 if [[ "$FILE" == *": zstd compressed data"* ]]; then
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" | \
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
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
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
91 echo "Install <readelf> utility to see more information" >>"$2" 2>&1
93 echo "----eof----" >>"$2" 2>&1
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 ))
106 if command -v chafa
>/dev
/null
2>&1; then
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
114 echo "Install <chafa> to see picture" >>"$2" 2>&1
117 if [[ "$FILE" == *"JPEG image"* ]] \
118 && [[ "$VCHAFA" == "no" ]]; then
119 if command -v jp2a
>/dev
/null
2>&1; then
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
130 echo "Install <jp2a> to see colored picture" >>"$2" 2>&1
134 if [[ "$VCHAFA" == "no" ]] \
135 && [[ "$VJP2A" == "no" ]]; then
136 if command -v asciiart
>/dev
/null
2>&1; then
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
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
152 echo "Install <exiftool> to see information" >>"$2" 2>&1
154 echo "----eof----" >>"$2" 2>&1
158 if [[ "$FILE" == *": Audio file"* ]]; then
159 if command -v exiftool
>/dev
/null
2>&1; then
160 exiftool
"$1" >>"$2" 2>&1
162 echo "Install <exiftool> to see information" >>"$2" 2>&1
164 echo "----eof----" >>"$2" 2>&1
168 if [[ "$FILE" == *": RIFF"*" data"* ]]; then
169 if command -v exiftool
>/dev
/null
2>&1; then
170 exiftool
"$1" >>"$2" 2>&1
172 echo "Install <exiftool> to see information" >>"$2" 2>&1
174 echo "----eof----" >>"$2" 2>&1
178 if [[ "$FILE" == *": BitTorrent file"* ]]; then
179 if command -v exiftool
>/dev
/null
2>&1; then
180 exiftool
"$1" >>"$2" 2>&1
182 echo "Install <exiftool> to see information" >>"$2" 2>&1
184 echo "----eof----" >>"$2" 2>&1
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
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
201 echo "Install <pandoc> to see document" >>"$2" 2>&1
203 echo "----eof----" >>"$2" 2>&1
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
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
220 echo "Install <pandoc> to see document" >>"$2" 2>&1
222 echo "----eof----" >>"$2" 2>&1
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
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
239 echo "Install <pandoc> to see document" >>"$2" 2>&1
241 echo "----eof----" >>"$2" 2>&1
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
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
259 echo "Install <pandoc> to see document" >>"$2" 2>&1
261 echo "----eof----" >>"$2" 2>&1
265 if [[ "$FILE" == *": Microsoft Word 2007+"* ]]; then
266 if command -v pandoc
>/dev
/null
2>&1; then
267 pandoc
"$1" >>"$2" 2>&1
269 echo "Install <pandoc> to see document" >>"$2" 2>&1
271 echo "----eof----" >>"$2" 2>&1
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
279 echo "Install <catdoc> to see document" >>"$2" 2>&1
281 echo "----eof----" >>"$2" 2>&1
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
289 echo "Install <catppt> to see document" >>"$2" 2>&1
291 echo "----eof----" >>"$2" 2>&1
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"
299 echo "Install <pdftotext> to see document" >>"$2" 2>&1
301 echo "----eof----" >>"$2" 2>&1
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
309 echo "Install <colordiff> to see colored diff" >>"$2" 2>&1
311 echo "----eof----" >>"$2" 2>&1
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
319 echo "Install <ctags> to see source overview" >>"$2" 2>&1
321 echo "----eof----" >>"$2" 2>&1
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
329 echo ............
>>"$2" 2>&1
330 tail -c 256 "$1" >>"$2" 2>&1
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
343 echo "Hint: use <F5> to switch back to raw file viewer" >>"$2" 2>&1