File: BFG.sh

package info (click to toggle)
clifm 1.26.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,816 kB
  • sloc: ansic: 64,595; sh: 3,133; python: 1,851; makefile: 567
file content (598 lines) | stat: -rwxr-xr-x 15,924 bytes parent folder | download
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
#!/bin/sh

# BFG: This is Clifm's file previewer script. It is called by the fzfnav.sh
# plugin for each hovered file. Variables for available applications are
# exported by fzfnav to prevent this script from checking the same
# applications once and again

# Written by L. Abramovich
# License: GPL2+

# Previewing dependencies (optional)
# atool or bsdtar or tar: archives
# magick (imagemagick 7.0+), and ueberzug (recommended) or viu or catimg or img2txt: images
# fontpreview or fontimage (fontforge): fonts
# libreoffice, catdoc, odt2txt, xls2csv, xls2xcsv, pandoc: office documents
# pdftoppm or pdftotext or mutool: PDF files
# epub-thumbnailer: epub files
# ddjvu (djvulibre) or djvutxt: DjVu files
# ghostscript: postscript files (ps)
# ffmpegthumbnailer: videos
# ffplay (ffmpeg) or mplayer or mpv: audio
# w3m or linx or elinks: web content
# glow: markdown
# bat or highlight or pygmentize: syntax highlighthing for text files
# python or jq: json
# transmission-cli: torrent files
# exiftool or mediainfo or file: file information

# Default size for images
WIDTH=1920
HEIGHT=1080


calculate_position() {
	# shellcheck disable=SC2034
	# TERM_LINES and TERM_COLS hold the number of lines and columns
	# of the terminal window respectivelly, while LINES and COLUMNS
	# refer rather to the preview window's size
	read -r TERM_LINES TERM_COLS << EOF
	$(</dev/tty stty size)
EOF

	X=$((TERM_COLS - COLUMNS - 2))

	if [ -z "$fzfheight" ]; then
		if [ -n "$CLIFM_FZF_HEIGHT" ]; then
			fzf_height="$(echo "$CLIFM_FZF_HEIGHT" | cut -d'%' -f1)"
		else
			fzf_height=80
		fi
	else
		fzf_height="$(echo "$fzfheight" | cut -d'%' -f1)"
	fi

	Y=$((TERM_LINES - (fzf_height * TERM_LINES / 100) + 1))
}

uz_image() {
	# shellcheck disable=SC2317
	calculate_position
	# shellcheck disable=SC2317
	printf '{"action": "add", "identifier": "clifm-preview", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "path": "%s"}\n' "$X" "$Y" "$COLUMNS" "$LINES" "$1" > "$FIFO_UEBERZUG"
}

uz_clear() {
	printf '{"action": "remove", "identifier": "clifm-preview"}\n' > "$FIFO_UEBERZUG"
}

kitty_clear() {
	kitty +kitten icat --clear --transfer-mode=stream --silent
}

preview_image() {
	[ -z "$IMG_VIEWER" ] || [ -z "$1" ] && return 1
	img="$1"
	case "$IMG_VIEWER" in
		kitty)
			calculate_position
			kitty +kitten icat --silent --place "$COLUMNS"x"$LINES"@"$X"x"$Y" \
				--transfer-mode=stream --align=left "$img" \
				&& return 0
		;;
		w3m)
			calculate_position
#			WIDTH=200
#			HEIGHT=200
#			X=360
#			Y=15
			W3IMG_PATH="/usr/lib/w3m/w3mimgdisplay"
			# Clear image
			printf '6;%s;%s;%s;%s\n3;' "$X" "$Y" "$WIDTH" "$HEIGHT" | "$W3IMG_PATH"
			printf '0;1;%s;%s;%s;%s;;;;;%s\n4;\n3;' "$X" "$Y" "$WIDTH" "$HEIGHT" \
			"$img" | "$W3IMG_PATH" && return 0
		;;
#		terminology)
#			[ "$TERM_PROGRAM" != "terminology" ] && return 1
#			tycat "$img" && return 0
#		;;
		pixterm) pixterm -s 2 -tc $((COLUMNS - 2)) "$img" && return 0 ;;
		catimg) catimg -H$LINES "$img" && return 0 ;;
		img2txt) img2txt -H$LINES -W$((COLUMNS - 2)) "$img" && return 0 ;;
		chafa) chafa -s "$((COLUMNS - 2))x$LINES" "$img" && return 0 ;;
		viu) viu -h$LINES -w$((COLUMNS - 2)) "$img" && return 0 ;;
		*) "$IMG_VIEWER" "$img" && return 0 ;;
	esac

	return 1
}

file_info() {
	[ "$FALLBACK_INFO" = 0 ] && exit 0

	[ -z "$1" ] && exit 1

	entry="$1"

	if [ "$FILE_OK" = 1 ] && [ "$FILE_HAS_MIME_ENCODING" = 1 ] && [ "$(file -bL --mime-encoding "$entry")" = "binary" ]; then
		printf -- "--- \e[0;30;47mBinary file\e[0m ---\n"
	fi

	if [ "$EXIFTOOL_OK" = 1 ]; then
		exiftool "$PWD/$entry" 2>/dev/null && exit 0
	elif [ "$MEDIAINFO_OK" = 1 ]; then
		mediainfo "$PWD/$entry" 2>/dev/null && exit 0
	elif [ "$FILE_OK" = 1 ]; then
		file -b "$entry" && exit 0
	fi
	exit 1
}

handle_ext() {
# Check a few extensions not correctly handled by file(1)
	entry="$1"

	ext="${entry##*.}"

	if [ -n "$ext" ] && [ "$ext" != "$entry" ]; then
		ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"

		case "$ext" in
			# Direct Stream Digital/Transfer (DSDIFF) and wavpack aren not
			# detected by file(1).
#			dff|dsf|wv|wvc)
#				file_info "$entry" && exit 0
#			;;

			# Markdown files
			md)
				if [ "$GLOW_OK" = 1 ]; then
					glow -s dark "$PWD/$entry" && exit 0
				elif [ "$MDCAT_OK" = 1 ]; then
					mdcat "$entry" && exit 0
				elif [ "$BAT_OK" = 1 ]; then
					bat "$entry" && exit 0
				elif [ "$CAT_OK" =  1 ]; then
					cat "$entry" && exit 0
				fi
			;;

			# XZ Compressed
			xz)
				if [ -n "$ARCHIVER_CMD" ]; then
					"$ARCHIVER_CMD" "$ARCHIVER_OPTS" "$entry" && exit 0
				fi
			;;

			# Web
			html|xhtml|htm)
				if [ -n "$BROWSER" ]; then
					"$BROWSER" -dump "$entry" && exit 0
				elif [ "$CAT_OK" = 1 ]; then
					cat "$entry" && exit 0
				fi
			;;

			json)
				if [ "$PYTHON_OK" = 1 ]; then
					python -m json.tool -- "$entry" && exit 0
				elif [ "$JQ_OK" = 1 ]; then
					jq --color-output . "$PWD/$entry" && exit 0
				elif [ "$CAT_OK" = 1 ]; then
					cat "$entry" && exit 0
				fi
			;;

			svg)
				[ -z "$IMG_VIEWER" ] && return
				if [ -f "$PREVIEWDIR/${entryhash}.png" ]; then
					preview_image "$PREVIEWDIR/${entryhash}.png" && exit 0
				fi

				[ -z "$CONVERT_OK" ] && return
				magick -background none -size "$WIDTH"x"$HEIGHT" "$entry" \
					"$PREVIEWDIR/${entryhash}.png"
				preview_image "${PREVIEWDIR}/${entryhash}.png" && exit 0
			;;

			torrent)
				if [ "$TRANSMISSION_OK" = 1 ]; then
					transmission-show -- "$PWD/$entry" && exit 0
				fi
			;;

#			stl|off|dxf|scad|csg)
#				if [ "$(which openscad 2>/dev/null)" ]; then
#					openscad "$PWD/$entry"
#				else
#					file_info "$entry"
#				fi
#				exit 1
#			;;
		esac
	fi
}

handle_mime() {

	[ -z "$FILE_OK" ] && return

	entry="$1"

	mimetype="$(file --brief --dereference --mime-type "$entry")"

	case "$mimetype" in

		# Office documents
		*officedocument*|*msword|*ms-excel|text/rtf|*.opendocument.*)

			if [ -n "$IMG_VIEWER" ] && [ -z "$DOCASTEXT" ]; then
				_type="png"
				if [ -f "$PREVIEWDIR/${entryhash}.$_type" ]; then
					preview_image "$PREVIEWDIR/${entryhash}.$_type" && exit 0
				fi

				if [ "$LIBREOFFICE_OK" = 1 ]; then
					libreoffice --headless --convert-to "$_type" "$entry" \
					--outdir "$PREVIEWDIR" > /dev/null 2>&1 && \

					mv "$PREVIEWDIR/${entry%.*}.$_type" "$PREVIEWDIR/${entryhash}.$_type" && \
					preview_image "${PREVIEWDIR}/${entryhash}.$_type" && exit 0
				fi
			fi

			case "$ext" in
				odt|ods|odp|sxw)
					# shellcheck disable=SC2153
					if [ "$ODT2TXT_OK" = 1 ]; then
						odt2txt "$PWD/$entry" && exit 0
					elif [ "$PANDOC_OK" = 1 ]; then
						pandoc -s -t markdown -- "$PWD/$entry" && exit 0
					fi
				;;
				xlsx)
					if [ "$XLSX2CSV_OK" = 1 ]; then
						xlsx2csv -- "$PWD/$entry" && exit 0
					fi
				;;
				xls)
					if [ "$XLSX2CSV_OK" = 1 ]; then
						xls2csv -- "$PWD/$entry" && exit 0
					fi
				;;
				docx)
					if [ "$UNZIP_OK" = 1 ]; then
						unzip -p "$entry" | grep --text '<w:r' | \
						sed 's/<w:p[^<\/]*>/ /g' | sed 's/<[^<]*>//g' | \
						grep -v '^[[:space:]]*$' | sed G && \
						exit 0
					fi
				;;
				*)
					if [ -n "$CATDOC_OK" ]; then
						catdoc "$entry" && exit 0
					fi
				;;
			esac
		;;

		# Empty file
		inode/x-empty)
			printf -- "--- \033[0;30;47mEmpty file\033[0m ---"
		;;

		# Web content
		text/html)
			if [ -n "$BROWSER" ]; then
				"$BROWSER" -dump "$entry" && exit 0
			elif [ "$PANDOC_OK" = 1 ]; then
				pandoc -s -t markdown -- "$entry" && exit 0
			elif [ "$CAT_OK" = 1 ]; then
				cat "$entry" && exit 0
			fi
		;;

		# Plain text files
		text/*|application/x-setupscript|*/xml)
			if [ "$BAT_OK" = 1 ]; then
				bat -pp --color=always "$entry" && exit 0
			elif [ "$HIGHLIGHT_OK" = 1 ]; then
				if [ "$COLORS" = 256 ]; then
					highlight -O xterm256 "$entry" && exit 0
				else
					highlight -O ansi "$entry" && exit 0
				fi
			elif [ "$PYGMENTIZE_OK" = 1 ]; then
				if [ "$COLORS" = 256 ]; then
					pigmentize -f terminal256 "$entry" && exit 0
				else
					pigmentize -f terminal "$entry" && exit 0
				fi
			elif [ "$CAT_OK" = 1 ]; then
				cat "$entry" && exit 0
			fi
		;;

		# DjVu
		*/vnd.djvu)
			if [ -n "$IMAGE_VIEWER" ] && [ "$DDJVU_OK" = 1 ]; then
				if [ -f "$PREVIEWDIR/${entryhash}.jpg" ]; then
					preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
				fi
				ddjvu --format=tiff --page=1 "$entry" "$PREVIEWDIR/${entryhash}.jpg"
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			elif [ "$DJVUTXT_OK" = 1 ]; then
				djvutxt "$PWD/entry" && exit 0
			fi
		;;

		# GIF files
		*/gif)
			[ -z "$IMG_VIEWER" ] && return

			if [ "$ANIMATE_GIFS" = 0 ]; then
				if [ "$IMG_VIEWER" = "kitty" ]; then
					calculate_position
					kitty +kitten icat --silent --place "$COLUMNS"x"$LINES"@"$X"x"$Y" \
						--transfer-mode=stream --align=left --loop=0 "$PWD/$entry" \
						&& exit 0
				fi
				if [ -f "$PREVIEWDIR/${entryhash}.jpg" ]; then
					preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
				fi

				magick "$entry"[0] -resize "$WIDTH"x"$HEIGHT"\> \
				"$PREVIEWDIR/$entryhash.jpg"
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
				exit 0
			fi

			if [ "$IMG_VIEWER" = "kitty" ] || [ "$IMG_VIEWER" = "catimg" ] \
			|| [ "$IMG_VIEWER" = "chafa" ]; then
				preview_image "$PWD/$entry" && exit 0
			fi

			# Break down the gif into frames and show each frame, one each 0.1 secs
#			printf "\n"
			filename="$(printf "%s" "$entry" | tr ' ' '_')"
			if [ ! -d "$PREVIEWDIR/$entryhash" ]; then
				mkdir -p "$PREVIEWDIR/$entryhash" && \
				magick "$entry" -coalesce -resize "$WIDTH"x"$HEIGHT"\> \
				"$PREVIEWDIR/$entryhash/${filename%.*}.jpg"
			fi
			while true; do
				for frame in $(find "$PREVIEWDIR/$entryhash"/*.jpg 2>/dev/null \
				| sort -V); do
					preview_image "$frame"
					sleep 0.1
				done
			done
			exit 0
		;;

		# Images
		image/*)
			preview_image "$PWD/$entry" && exit 0
		;;

		# Postscript
		application/postscript)
			[ -z "$IMG_VIEWER" ] && return

			if [ -f "$PREVIEWDIR/${entryhash}.jpg" ]; then
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			fi

			if [ "$(which gs 2>/dev/null)" ]; then
				gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 \
				-sOutputFile="$PREVIEWDIR/${entryhash}.jpg" "$entry" > /dev/null 2>&1 && \
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			fi
		;;

		# Epub
		application/epub+zip|application/x-mobipocket-ebook|application/x-fictionbook+xml)
			[ -z "$IMG_VIEWER" ] && return

			if [ -f "$PREVIEWDIR/${entryhash}.jpg" ]; then
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			fi

			if [ -n "$EPUBTHUMB_OK" ]; then
				epub-thumbnailer "$entry" "$PREVIEWDIR/${entryhash}.jpg" \
				"$WIDTH" "$HEIGHT" && \
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			fi
		;;

		# PDF
		*/pdf)
			[ -z "$IMG_VIEWER" ] && return

			if [ -f "$PREVIEWDIR/${entryhash}.jpg" ] && \
			[ "$PDFTOPPM_OK" = 1 ]; then
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			fi

			if [ "$PDFTOPPM_OK" = 1 ]; then
				pdftoppm -jpeg -f 1 -singlefile "$entry" "$PREVIEWDIR/$entryhash" && \
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			elif [ "$PDFTOTEXT_OK" = 1 ]; then
				pdftotext -nopgbrk -layout -- "$entry" - | ${PAGER:=less} && exit 0
			elif [ "$MUTOOL_OK" = 1 ]; then
				mutool draw -F txt -- "$entry" && exit 0
			fi
		;;

		# Audio
		audio/*)
#			[ -z "$IMG_VIEWER" ] || ! [ "$(which ffmpeg 2>/dev/null)" ] && return

#			ffmpeg -i "$entry" -lavfi \
#			showspectrumpic=s="$WIDTH"x"$HEIGHT":mode=separate:legend=disabled \
#			"${PREVIEWDIR}/${entry}.jpg" > /dev/null 2>&1

#			uz_image "${PREVIEWDIR}/${entry}.jpg" ;;
			if [ "$FFPLAY_OK" = 1 ]; then
				ffplay -nodisp -autoexit "$entry" &
			elif [ "$MPLAYER_OK" = 1 ]; then
				mplayer "$entry" &
			elif [ "$MPV_OK" = 1 ]; then
				mpv --no-video --quiet "$entry" &
			fi

			if [ "$FALLBACK_INFO" = 1 ]; then
				[ "$MEDIAINFO_OK" = 1 ] && mediainfo "$entry"
				[ "$EXIFTOOL_OK" = 1 ] && exiftool "$entry"
			fi

			exit 0
		;;

		# Video
		video/*)
			[ -z "$IMG_VIEWER" ] && return

			if [ -f "$PREVIEWDIR/${entryhash}.jpg" ]; then
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			fi

			if [ "$FFMPEGTHUMB_OK" = 1 ]; then
				ffmpegthumbnailer -i "$entry" -o "$PREVIEWDIR/${entryhash}.jpg" -s 0 \
				-q 5 2>/dev/null && \
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			fi
		;;

		# Fonts
		font/*|application/font*|application/*opentype)
			[ -z "$IMG_VIEWER" ] && return

			if [ -f "${PREVIEWDIR}/${entryhash}.jpg" ]; then
				preview_image "${PREVIEWDIR}/${entryhash}.jpg" && exit 0
			elif [ -f "${PREVIEWDIR}/${entryhash}.png" ]; then
				preview_image "${PREVIEWDIR}/${entryhash}.png" && exit 0
			fi

			if [ "$FONTPREVIEW_OK" = 1 ]; then
				fontpreview -i "$entry" -o "$PREVIEWDIR/${entryhash}.jpg" && \
				preview_image "$PREVIEWDIR/${entryhash}.jpg" && exit 0
			elif [ "$FONTIMAGE_OK" = 1 ]; then
				png_file="$PREVIEWDIR/${entryhash}.png"
				if fontimage -o "$png_file" \
						--width "500" --height "290" \
						--pixelsize "45" \
						--fontname \
						--pixelsize "30" \
						--text "  ABCDEFGHIJKLMNOPQRSTUVWXYZ  " \
						--text "  abcdefghijklmnopqrstuvwxyz  " \
						--text "     0123456789.:,;(*!?')  " \
						--text "        ff fl fi ffi ffl  " \
						--text " The quick brown fox jumps over the lazy dog." \
						"$PWD/$entry" > /dev/null 2>&1;
				then
					preview_image "$png_file" && exit 0
				fi
			fi
		;;

		# Archives
		application/zip|application/gzip|application/x-7z-compressed|\
		application/x-bzip2)
			if [ -n "$ARCHIVER_CMD" ]; then
				"$ARCHIVER_CMD" "$ARCHIVER_OPTS" "$entry" && exit 0
			fi
		;;
	esac
}

main() {
	entry="$1"

	[ "$entry" = ".." ] && return

	if [ "$USE_PISTOL" = 1 ]; then
		pistol "$PWD/$entry" && exit 0
		exit 1
	fi

	if [ "$USE_SCOPE" = 1 ] && [ -x "$SCOPE_FILE" ]; then
		calculate_position
		"$SCOPE_FILE" "$PWD/$entry" "$X" "$Y" "$PREVIEWDIR" "True" && exit 0
		exit 1
	fi

	[ "$UEBERZUG_OK" = 1 ] && uz_clear
	[ "$IMG_VIEWER" = "kitty" ] && kitty_clear

	# Symlink
	if [ -L "$entry" ]; then
		real_path="$(realpath "$entry")"
		printf "%s \033[1;36m->\033[0m " "$entry"
		if [ -e "$real_path" ]; then
			if [ "$POSIX_LS" = 0 ]; then
				ls -d --color=always "$real_path" && exit 0
			else
				ls -d "$real_path" && exit 0
			fi
		else
			printf "%s\n\033[1;37mBroken link\033[0m" "$real_path" && exit 0
		fi
		exit 1
	fi

	# Directory
	if [ -d "$entry" ]; then
		path="$(printf "%s" "$(pwd)/$entry" | sed "s;//;/;")"
		if [ "$DIR_CMD" = "tree" ]; then
			if [ "$COLORS" = 256 ]; then
				tree -a "$path" && exit 0
			else
				tree -aA "$path" && exit 0
			fi
		else
			printf  "%s\n" "$path"
			if [ "$DIR_CMD" = "lsd" ]; then
				lsd -A --group-dirs=first --color=always "$path" && exit 0
			elif [ "$DIR_CMD" = "lsd-tree" ]; then
				lsd -A --group-dirs=first --depth=1 --tree --color=always "$path" && exit 0
			elif [ "$DIR_CMD" = "exa" ]; then
				exa -G --group-directories-first --color=always "$path" && exit 0
			elif [ "$DIR_CMD" = "exa-tree" ]; then
				exa -G --group-directories-first --color=always --tree --level=1 "$path" && exit 0
			else
				if [ "$POSIX_LS" = 0 ]; then
					ls -Ap --color=always --indicator-style=none "$path" && exit 0
				else
					ls -Ap "$path" && exit 0
				fi
			fi
		fi
		exit 1
	fi

	printf "\n"

	# Use hashes instead of file names for cached files
	if type md5sum > /dev/null 2>&1; then
		entryhash="$(printf "file://%s" "${PWD}/$entry" | md5sum)"
		entryhash="${entryhash%% *}"
	elif type md5 > /dev/null 2>&1; then
		entryhash="$(md5 -q -s "file://${PWD}/$entry")"
	else
		printf "clifm: No hashing application found. Either md5sum or md5 \
are required\n" >&2
		exit 1
	fi

	# Do not generate previews of previews
	[ "$PWD" = "${PREVIEWDIR}" ] && entry="${entry%.*}"

	handle_ext "$entry"
	handle_mime "$entry"
	file_info "$entry" # Fallback to file information
}

#calculate_position
main "$@"
exit 1