Dealing with images in Ranger

Forum rules
Share your brain ;)
User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Dealing with images in Ranger

Unread post by Snap » 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:

Code: Select all

0 | sxiv -- "$@"
1 | feh -- "$@"
These are the first two mime types for image viewers. Defined in rifle.conf like this:

Code: Select all

mime ^image, has sxiv,      X, flag f = sxiv -- "$@"
mime ^image, has feh,       X, flag f = feh -- "$@"
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):
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... what a cool name, huh?

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 -- "$@"
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

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}"
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

Code: Select all

#!/bin/bash
/usr/local/bin/feh-browser %f -F -Z
For timed slideshows:

feh-s

Code: Select all

#!/bin/bash
/usr/local/bin/feh-browser %f -F -Z -x -q -Y -D 3 .
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:

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 -- "$@"
enjoy!

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: Dealing with images in Ranger

Unread post by GekkoP » Wed Nov 18, 2015 12:37 pm

Oh look at that. Thanks for sharing.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Dealing with images in Ranger

Unread post by rhowaldt » Wed Nov 18, 2015 1:34 pm

Oh, snap! that's wonderful :) - thanks for researching this shit! meh looks nice, and good name too!
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Dealing with images in Ranger

Unread post by franksinistra » Wed Nov 18, 2015 3:07 pm

Thanks snappy! now i can get http://git.2f30.org/lel work in ranger
rice no more.

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: Dealing with images in Ranger

Unread post by Snap » Thu Nov 19, 2015 1:22 am

Hey, thanks for pointing out lel, Mr. sinistra. Another nice name. Do you know if gif support means animated gifs or just plain gif? I'll keep an eye on it.

EDIT: sxvi does animated gifs nicely. Wish I knew another way with feh or meh (via imagemagick?) and forget about sxvi.
Last edited by Snap on Thu Nov 19, 2015 10:31 am, edited 1 time in total.

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Dealing with images in Ranger

Unread post by wuxmedia » Thu Nov 19, 2015 9:16 am

yeah nice work Snapper
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Dealing with images in Ranger

Unread post by franksinistra » Thu Nov 19, 2015 8:45 pm

Snap wrote:Hey, thanks for pointing out lel, Mr. sinistra. Another nice name. Do you know if gif support means animated gifs or just plain gif? I'll keep an eye on it.

EDIT: sxvi does animated gifs nicely. Wish I knew another way with feh or meh (via imagemagick?) and forget about sxvi.
to answer your question https://github.com/eXeC64/imv
rice no more.

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: Dealing with images in Ranger

Unread post by Snap » Fri Nov 20, 2015 9:04 am

Fuck yeah! Thanks, fs.

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: Dealing with images in Ranger

Unread post by Snap » Fri Nov 20, 2015 10:33 am

Found this about imv:
It doesn't work with ranger the same way other viewers do. imv -- "$@" but removing the -- seems to work. I'm not sure how it would make a difference but I'm no expert.
Haven't tried it yet whatsoever. About to compile and check.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Dealing with images in Ranger

Unread post by dkeg » Sat Nov 21, 2015 8:59 pm

bonus - vim like keybindings

Work hard; Complain less

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: Dealing with images in Ranger

Unread post by Snap » Sun Nov 22, 2015 8:46 am

Yup. Ranger made me install vim. Finally learning that shit.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Dealing with images in Ranger

Unread post by dkeg » Sun Nov 22, 2015 2:24 pm

there's really no reason for ranger. Put this in your .bashrc and you're good to go

Code: Select all

# Automatically do an ls after each cd
cd() {
  if [ -n "$1" ]; then
builtin cd "$@" && ls --group-directories-first
  else
builtin cd ~ && ls --group-directories-first      
  fi                                              
}

Work hard; Complain less

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Dealing with images in Ranger

Unread post by wuxmedia » Mon Nov 23, 2015 9:57 am

^ not that I view images on servers, but yes generally

Code: Select all

cd /path/ ;ls
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: Dealing with images in Ranger

Unread post by Snap » Mon Nov 23, 2015 11:38 am

Nice trick. Thanks, dkeg.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Dealing with images in Ranger

Unread post by dkeg » Mon Nov 23, 2015 1:16 pm

It is either already in default bbq spins or was at some point. That's where I got it from, but I've been using the same .bashrc for years

Work hard; Complain less

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: Dealing with images in Ranger

Unread post by Snap » Mon Nov 23, 2015 2:57 pm

Maybe it was in past spins. I've never saw it in any .bashrc in the spins I've tried. Thanks for rescuing it for the masses.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Dealing with images in Ranger

Unread post by rhowaldt » Mon Nov 23, 2015 3:45 pm

yeah should be in default .bashrc usually. iirc i once made that...
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Dealing with images in Ranger

Unread post by pidsley » Fri Nov 27, 2015 5:20 pm

This works too:

Code: Select all

cd() {
	builtin cd $@ && ls
}
No need for the conditional code. It uses whatever alias you have already defined for "ls", so if you want directories first, alias ls:

Code: Select all

alias ls='ls -F --color=auto --group-directories-first'

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Dealing with images in Ranger

Unread post by wuxmedia » Fri Nov 27, 2015 6:56 pm

^ then you find out 'ls' is actually symlinked to a bash scripts: 'echo * | grep fmt -1'
and your mind begins to melt...
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Dealing with images in Ranger

Unread post by franksinistra » Sat Nov 28, 2015 2:10 am

add dircolors (if that's your thing) to make ls --color=auto colorful and interesting.
rice no more.

Post Reply