Dealing with images in Ranger
Posted: Wed Nov 18, 2015 12:25 pm
If you don't run the X, or your beard is untidy like a spiritual leader's beard you surely won't care about any of this. But if your beard is boring and regular like mine and use ranger just keep going.
if you select an image file in ranger (on its defaults) and hit r, you'll get this:
These are the first two mime types for image viewers. Defined in rifle.conf like this:
sxiv is in the repos. It does the job, though I personally don't quite like it.
The infamous feh is in the repos too. It's hated and loved by many. The problem it has for this use is that it fucking goes full resolution instead of full screen it can be really annoying. z3bra hates it (introducing meh):
meh is lighter (less dependencies) than sxiv, it's frigging awesome and can be a good replacement for feh (but more on feh later). It's not in the repos, but it's easy to compile. I don't like dealing with lists, so to open an image it's just great (as z3bra stated), but not that good for slideshows or scrolling images IMHO.
To enable it just add this line into ~/.config/ranger/rifle.conf
Ok. we can open images at window size and resize them at will. But, what if we want to do a slideshow or surfing images within a directory without needing to do lists? Easy: feh. Yes, feh. The old feh plus a small script and a couple of wrappers.
Here the script:
feh-browser
For GTK browsers this is (should be) enough to display the images at fullscreen instead of full scaled, but ranger keeps doing full scale. Still annoying. But we can use a couple of wrappers to make it happen.
To scroll or navigate all the images into a directory (with left/right arrow keys (up/down to zoom), left mouse clicks or mouse scrolling) use this one:
feh-b
For timed slideshows:
feh-s
Set the delay at will in advance and then run it so now your hands will be free for wan... eeerm... slideshow pictures. the keystrokes and mouse actions still work as above, but they images will flow for you if your hands are busy.
My rifle:
enjoy!
if you select an image file in ranger (on its defaults) and hit r, you'll get this:
Code: Select all
0 | sxiv -- "$@"
1 | feh -- "$@"
Code: Select all
mime ^image, has sxiv, X, flag f = sxiv -- "$@"
mime ^image, has feh, X, flag f = feh -- "$@"
The infamous feh is in the repos too. It's hated and loved by many. The problem it has for this use is that it fucking goes full resolution instead of full screen it can be really annoying. z3bra hates it (introducing meh):
meh... what a cool name, huh?I've spit on feh before (see hsetroot. I have effectively some problems with it. Feh is impossible to use. it displays the images in full size, no matter what the window size is. And that's freaking annoying... I just want my image viewer to display an image at the maximum size for the window, and to resize when I change the window size.
That is what meh does. And (almost) nothing more ! Meh take a list of images as arguments, and fits them in its window. Meh can also read a list from stdin. You can then cycle through images using h,j,k,l,left,down,up,right.
When you press <enter>, meh outputs the current image name to stdout. It allows cool stuffs like meh *.jpg | xargs rm to delete the images upon pressing <enter>.
meh is lighter (less dependencies) than sxiv, it's frigging awesome and can be a good replacement for feh (but more on feh later). It's not in the repos, but it's easy to compile. I don't like dealing with lists, so to open an image it's just great (as z3bra stated), but not that good for slideshows or scrolling images IMHO.
To enable it just add this line into ~/.config/ranger/rifle.conf
Code: Select all
mime ^image, has meh, X, flag f = meh -- "$@"
Here the script:
feh-browser
Code: Select all
#!/bin/bash
#nvoke it with the image path, e.g. "/path/to/script %f -F -Z".
#It should open that image in feh and let you browse through other images in the folder in the usual order, i.e. "feh /path/to/dir/*".
# Change the input field separator to avoid problems with spaces.
IFS='
'
# Get the target file, its name, directory, and the other files in the
directory.
_fpath="${1/%\/}"
_fname="$(basename "$_fpath")"
_dpath="$(dirname "$_fpath")"
_flist=($(ls "$_dpath"))
# Determine the index of the target file in the file list array.
_i=0
for _file in "${_flist[@]}"; do
[ "$_file" == "$_fname" ] && break
_i=$(($_i + 1))
done
# Remove the target file from the arguments, leaving any eventual arguments to
# feh.
shift
# Change to the directory and launch feh with the target file as the first
# argument, and the rest of the files in their normal order.
cd "$_dpath"
feh "$@" "${_flist[@]:$_i}" "${_flist[@]:0:$_i}"
To scroll or navigate all the images into a directory (with left/right arrow keys (up/down to zoom), left mouse clicks or mouse scrolling) use this one:
feh-b
Code: Select all
#!/bin/bash
/usr/local/bin/feh-browser %f -F -Z
feh-s
Code: Select all
#!/bin/bash
/usr/local/bin/feh-browser %f -F -Z -x -q -Y -D 3 .
My rifle:
Code: Select all
#-------------------------------------------
# Image Viewing:
#-------------------------------------------
mime ^image, has meh, X, flag f = meh -- "$@"
mime ^image, has feh-b, X, flag f = feh-b -- "$@"
mime ^image, has feh-s, X, flag f = feh-s -- "$@"
mime ^image, has gimp, X, flag f = gimp -- "$@"
ext xcf, X, flag f = gimp -- "$@"