Ranger, a console file manager that can be operated with Vim-like key bindings, has a fast live preview, as well as text content, images and settings. You can also check thumbnails of PDF documents and videos on a crisp terminal.
In order to realize image display with the viewer, you can use the image display mechanism of w3m w3mimgdisplay and iTerm2 of Mac, but recently I learned that it also supports a tool called Überzug
, so this tool itself and Ranger I would like to introduce how to combine with.
Überzug is a command line utility that allows you to draw images on the terminal using child windows, and according to the readme, it has the following features.
--There are no race conditions because a new window is created to display the image. --The Expose event is processed, so the image is redrawn when you switch workspaces. --Supported for use on tmux.
And so on. Let's use it immediately.
It is a Python tool and is installed with pip, but it depends on X11 and Xext, so it seems that it can only be used on an OS running on the X Window System. I tried it on ʻUbuntu 20.04 LTS`. I could install it on WSL2 & x410 (X server for WSL), but it did not work properly due to an error.
Follow the steps below to install the required libraries and Überzug.
~% sudo apt-get install python3 python3-dev libx11-dev libxext-dev python3-distutil
~% curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
~% sudo python3 get-pip.py
~% sudo pip3 install ueberzug
If you can install it successfully, prepare the following script as a trial and use it from the shell.
It renders using the X
feature, so you probably don't care what kind of terminal emulator you have.
show.sh
#!/bin/bash
[ -z "$5" ] && echo "Usage: $0 <image> <x> <y> <max height> <max width>" && exit
source "`ueberzug library`"
ImageLayer 0< <(
ImageLayer::add [identifier]="example0" [x]="$2" [y]="$3" [max_width]="$5" [max_height]="$4" [path]="$1"
read
)
If you do chmod + x show.sh
and hit it like ./show.sh images / AX141105107519_TP_V4.jpg 50 10 20 20
,
You can display an image in any size anywhere on the terminal like this. Hit [Enter] again to exit.
There seem to be various other options, so please refer to Github for details.
Let's check the template of $ HOME / .config / ranger / rc.conf
after ranger --copy-config = all
in Ranger 1.9.3
.
$HOME/.config/ranger/rc.conf
# * ueberzug:
# Preview images in full color with the external command "ueberzug".
# Images are shown by using a child window.
# Only for users who run X11 in GNU/Linux.
Since there is a comment, set set preview_images_method
as follows.
set preview_images_method ueberzug
This is OK.
You can preview "image / PDF / video thumbnails" at explosive speed like this.
It seems that there is no problem even if you display in each pane divided by tmux or switch windows. The image will not disappear or remain.
I was able to display images in the same way with Ranger launched in Vim's terminal mode, so I think that I haven't tried it with a plug-in that works with Ranger, but I think it can be used.
Currently, the operating systems that can be used are limited, but if you are a regular user of Linux Desktop, you can use it very conveniently. Personally, I would like to be able to use it with a combination of Windows 10 (WSL2) and X server.
Then, please give it a try!