How to preview images in Ranger file manager with iTerm and Tmux
How to preview images in Ranger file manager with iTerm and Tmux
I have been avare of ranger as a file system browser for quite some time.
Once you have installed ranger - go and edit following file ~/.config/ranger/rc.conf.
1
2
3
4
5
6
7
8
9
10
vim ~/.config/ranger/scope.conf
...
# How many columns are there, and what are their relative widths?
set column_ratios 1,2,5
...
set preview_images true
set use_preview_script true
set preview_images_method iterm2
...
:wq!
Then it’s importnat to setup html and json/terrafrom like files in ~/.config/ranger/scope.conf
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
vim ~/.config/ranger/scope.conf
...
## HTML
htm|html|xhtml)
## Preview as text conversion
# w3m -dump "${FILE_PATH}" && exit 5
# lynx -dump -- "${FILE_PATH}" && exit 5
# elinks -dump "${FILE_PATH}" && exit 5
pandoc -s -t markdown -- "${FILE_PATH}" && exit 5
;;
## JSON
json|tfstate)
jq --color-output . "${FILE_PATH}" && exit 5
python -m json.tool -- "${FILE_PATH}" && exit 5
;;
...
...
image/*)
local orientation
orientation="$( identify -format '%[EXIF:Orientation]\n' -- "${FILE_PATH}" )"
## If orientation data is present and the image actually
## needs rotating ("1" means no rotation)...
if [[ -n "$orientation" && "$orientation" != 1 ]]; then
## ...auto-rotate the image according to the EXIF data.
convert -- "${FILE_PATH}" -auto-orient "${IMAGE_CACHE_PATH}" && exit 6
convert -- "${FILE_PATH}" -quality 25 -resize 1080 -auto-orient "${IMAGE_CACHE_PATH}" && exit 6
else
convert -- "${FILE_PATH}" -quality 25 -resize 1080 "${IMAGE_CACHE_PATH}" && exit 6
fi
## `w3mimgdisplay` will be called for all images (unless overriden
## as above), but might fail for unsupported types.
exit 7;;
## Video
...
:wq!
And lastly I would recomend to edit ~/.config/ranger/rifle.conf file because html files were opened by elinks by default. I have changed it to vim editor.
Please add one line of code at the very begining in this file: ~/.config/ranger/rifle.conf
1
2
3
4
5
6
vim ~/.config/ranger/rifle.conf
...
ext x?html?, has vim, terminal = ${VISUAL:-$EDITOR} -- "$@"
...
:wq!
This post is licensed under CC BY 4.0 by the author.
