blob: fbe0431c27af2ac0c9ec825df25e29639f238766 (
plain)
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
|
#!/bin/bash -
#===============================================================================
#
# FILE: vifm-imagepreview.sh
#
# USAGE: ./vifm-imagepreview.sh
#
# DESCRIPTION: Image previewer for vifm.
# Based on script by z3bra -- 2014-01-21
# This is called by vifm by adding the following line to vimfrc file:
#
# fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm vifm-imagepreviewer.sh %px %py %pw %ph %c
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Vito G. Graffagnino (), v.graffagnino@btinternet.com
# ORGANIZATION:
# CREATED: 04/05/17 11:19:39
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
W3MIMGDISPLAY="/usr/lib64/w3m/w3mimgdisplay"
FONTH=15 # Size of one terminal row
FONTW=7 # Size of one terminal column
X=$1
Y=$2
COLUMNS=$3
LINES=$4
FILENAME=$5
read width height <<< `echo "5;$FILENAME" | $W3MIMGDISPLAY`
if [ -z "$width" -o -z "$height" ]; then
echo 'Error: Failed to obtain image size.'
exit 1
fi
x=$((FONTW * X))
y=$((FONTH * Y))
max_width=$((FONTW * COLUMNS))
max_height=$((FONTH * LINES))
if [ "$width" -gt "$max_width" ]; then
height=$((height * max_width / width))
width=$max_width
fi
if [ "$height" -gt "$max_height" ]; then
width=$((width * max_height / height))
height=$max_height
fi
w3m_command="0;1;$x;$y;$width;$height;;;;;$FILENAME\n4;\n3;"
echo -e "$w3m_command" | $W3MIMGDISPLAY
|