Ranger Image Preview With Tmux on macOS

Screenshot

Ranger file manager inside a tmux window, with image preview shown in the right.

What Is Ranger. Why Use it to Preview Images?:

Ranger is a terminal-based file browser that uses key vim bindings. It’s a fast keyboard-driven way to manage files within a terminal. Unfortunately, One feature that ranger lacks ‘out of the box’ is the ability to preview images. This makes managing image files a pain. Fortunately, with some configoration, ranger can show previews of images inside the terminal emulator (even if ranger is started within tmux). It requires using a different terminal emulator than the default one in macOS and installing some extra packages.

Install iTerm2:

Download and install Iterm2 or supported browser for Sixel support. iTerm2 supports rendering abilities not available to terminal. You won’t be able to see image preview in the default macOS terminal

Build Ranger from Source Instead of from Homebrew:

Since the Homebrew package breaks, build Ranger manually:

 git clone https://github.com/ranger/ranger.git
 cd ranger
 sudo make install

When I used the ranger installed from homebrew I got error messages even after reinstalling the package. I’m guessing it has to do with python3 incompatibility in the brew version of ranger. When I built ranger from github, instead of using homebrew, Sixel worked fine.

Install libsixel and Image Magick:

Use Homebrew to install these dependencies:

brew install libsixel imagemagick

Libsixel handles Sixel encoding, while image magick is used for image processing.

Configure Ranger for Sixel Previews

Open or create Ranger’s configuration file:

vim ~/.config/ranger/rc.conf

Add the following lines to enable Sixel previews:

set preview_images true
set preview_images_method sixel

Save and exit.

Test Your Setup:

Notes:

If you download iTerm2 and don’t need to use tmux, you can get ranger to preview images using iTerm’s own built-in rendering. This does not require installing libsixel or imagemagnick, but in this configuration images will not render within ranger inside tmux.

To use iTerm2’s own rendering, understanding that it breaks tmux, simply edit the rc.conf file of ranger. This method does not require downloading extra packages and can be used with the homebrew vesion of ranger.

set preview_images true
set preview_images_method iterm2
Tags: