You are not logged in.

#1 2011-01-27 23:39:48

Eiki
Member
Registered: 2009-10-08
Posts: 19

[SOLVED]Using feh to browse images

I'm trying to use feh to browse images, as I'm sure you could gather from the subject. I want to be able to click on an image in a folder and then be able to use the left and right arrow keys to browse the other images in that folder. I would think that this would be fairly easy to figure out but I've spent way too much time googling this and haven't really found exactly what I'm looking for.

I found this old forum post asking to do the same thing. The last post mentions implementing this with Thunar (which would be great since that's what I use) but it mentions the use of a "%d" parameter, which I can not see mention of in the feh manpage. Also the little shell script is nice but it just starts browsing the images from the first file in the directory, not what I'm looking for. Is there a way to do this without a shell script?

Last edited by Eiki (2011-01-28 16:26:48)

Offline

#2 2011-01-27 23:52:43

fsckd
Forum Moderator
Registered: 2009-06-15
Posts: 3,575

Re: [SOLVED]Using feh to browse images

The %d is handled by Thunar, not feh.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Online

#3 2011-01-28 00:07:51

Eiki
Member
Registered: 2009-10-08
Posts: 19

Re: [SOLVED]Using feh to browse images

Well shoot, that would explain why I didn't see it in the feh manpage, wouldn't it?

So by using the custom command "feh -F -Z %d", I got the image to open up and then I could cycle through the images, which is fine, but they're all out of order. I tried "feh -F -Z -S filename %d" and it starts from the beginning of the folder, which is not what I want. Any other suggestions out there?

Offline

#4 2011-01-28 00:33:15

karol
Archivist
Registered: 2009-05-06
Posts: 25,432

Re: [SOLVED]Using feh to browse images

I think '%d' is a Thunar custom action parameter.

Offline

#5 2011-01-28 03:00:01

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 5,725
Website

Re: [SOLVED]Using feh to browse images

*edit*
This is now on the Feh wiki page.

Try this:

  #!/bin/bash
  
  # 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}"

Invoke 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/*".

Last edited by Xyne (2011-01-28 15:46:19)

Offline

#6 2011-01-28 06:58:01

Eiki
Member
Registered: 2009-10-08
Posts: 19

Re: [SOLVED]Using feh to browse images

Hey thanks a lot, it works perfectly. I really appreciate it. I hate to admit it but my scripting skills are pretty much nonexistent at this point but I am trying to learn. Ha, I guess this'll give me something to study.

Offline

#7 2011-01-28 11:56:52

Eiki
Member
Registered: 2009-10-08
Posts: 19

Re: [SOLVED]Using feh to browse images

One final chime-in from me, do you guys think it would be worth it for me to add that script to the feh wiki page?

Offline

#8 2011-01-28 14:59:36

penguin
Member
From: Gotham City
Registered: 2010-12-31
Posts: 116

Re: [SOLVED]Using feh to browse images

You mean the arch wiki?
https://wiki.archlinux.org/index.php/Feh

I think it sounds like a swell idea, if Xyne approves.

Offline

#9 2011-01-28 15:42:53

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,079

Re: [SOLVED]Using feh to browse images

yes please. Please give Xyne the appropriate credit though. Forum threads tend to get lost after a while, if it's on the wiki, it will be much more accessible.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#10 2011-01-28 15:49:48

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 5,725
Website

Re: [SOLVED]Using feh to browse images

I've added it to the wiki. I've also made some changes to the script:

  • added comments

  • all arguments after the filepath are now passed to feh, e.g. "/path/to/script %f -F -Z"

Offline

#11 2011-01-28 16:25:35

Eiki
Member
Registered: 2009-10-08
Posts: 19

Re: [SOLVED]Using feh to browse images

Ah, looks like I was beaten to the punch. Just wanted to give a little back so that I wasn't just being a help vampire there.

Thanks a lot also for the addition of comments. Helps a lot with the learning and whatnot.

Offline

#12 2011-01-28 16:37:53

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 5,725
Website

Re: [SOLVED]Using feh to browse images

Eiki wrote:

Ah, looks like I was beaten to the punch. Just wanted to give a little back so that I wasn't just being a help vampire there.

You did research before posting, so you're not a help vampire. wink

I just noticed that you asked for a way to do this "without a shell script"... oops.

Eiki wrote:

Thanks a lot also for the addition of comments. Helps a lot with the learning and whatnot.

If you have any questions, feel free to post them here or send me a message.

Offline

#13 2011-01-28 17:25:52

Eiki
Member
Registered: 2009-10-08
Posts: 19

Re: [SOLVED]Using feh to browse images

Xyne wrote:

You did research before posting, so you're not a help vampire. wink

I just noticed that you asked for a way to do this "without a shell script"... oops.

Ha thanks. I definitely did try researching this before posting. I had found this thread from the Ubuntu forums with Google, discussing this very issue. I was wondering if there might be a simpler approach to this, hence why I asked if it was possible without a shell script. I had tried looking through the feh manpage to see if it was possible but didn't see a solution there.

I can definitely live with your shell script cause I'll at least be able to sit down and decipher it, unlike the one in the thread I just linked which has a solution written up in ruby (which I don't know two shakes about).


Xyne wrote:

If you have any questions, feel free to post them here or send me a message.

Will do smile

Last edited by Eiki (2011-01-28 17:26:26)

Offline

#14 2011-02-01 06:33:59

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: [SOLVED]Using feh to browse images

Xyne wrote:

I've added it to the wiki. I've also made some changes to the script:

You've also broken the script wink

My bash foo is inferior, but when I use the wiki script I get:

/home/thayer/bin/fehbrowse: line 5: [[ !: command not found

feh loads, but displays the first image in the directory, not the one specified on the command line.  The original script posted above however appears to work as expected.


thayer williams ~ cinderwick.ca

Offline

#15 2011-02-01 10:32:52

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 5,725
Website

Re: [SOLVED]Using feh to browse images

thayer wrote:
Xyne wrote:

I've added it to the wiki. I've also made some changes to the script:

You've also broken the script wink

Look at the edit history. Lavandero broke it. If it weren't broken, I would be upset that he deleted the part that credits me as the original author.

Here's what I posted:
https://wiki.archlinux.org/index.php?ti … did=129228

*edit*
Here's a working version that incorporates Lavandero's changes: https://wiki.archlinux.org/index.php?ti … did=129544
I've also made some notes on the discussion page.

Last edited by Xyne (2011-02-01 11:07:44)

Offline

#16 2011-02-01 15:42:38

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: [SOLVED]Using feh to browse images

Xyne wrote:
thayer wrote:
Xyne wrote:

I've added it to the wiki. I've also made some changes to the script:

You've also broken the script wink

Look at the edit history. Lavandero broke it.

Oops, thought you might have a different nick for the wiki (some of us do) and I didn't scroll down far enough to see otherwise.   

Xyne wrote:

Here's a working version that incorporates Lavandero's changes: https://wiki.archlinux.org/index.php?ti … did=129544
I've also made some notes on the discussion page.

Thanks for the fix and I couldn't agree more about your comments.


thayer williams ~ cinderwick.ca

Offline

#17 2011-02-02 08:35:37

penguin
Member
From: Gotham City
Registered: 2010-12-31
Posts: 116

Re: [SOLVED]Using feh to browse images

The script works fine for me, but with the version I copied yesterday (sometime during 12:00-17:00 Feb 1`) I get this warning:

 
 vandelay ~ $ ./feh2.sh zen.png 
./feh.sh: line 5: [[ !: command not found

Just tried it again on a different computer, and that works fine. I'll try again on the other computer when I get home.

-q is another good argument for this script, since it suppresses any warnings if there are non-image files in the same folder (when browsing with the script). (perhaps that should be added to the wiki?)

Oops, thought you might have a different nick for the wiki (some of us do) and I didn't scroll down far enough to see otherwise.

I've noticed that it is difficult to have the same nick on AUR, Forum, and Wiki. I wish one could have the same on all three, since that would make everything a lot easier for everybody.

Offline

#18 2011-02-09 14:23:49

penguin
Member
From: Gotham City
Registered: 2010-12-31
Posts: 116

Re: [SOLVED]Using feh to browse images

penguin wrote:

...perhaps that should be added to the wiki?

I added it my self to the wiki. Hope this was OK:

ArchWiki wrote:

"-F" and "-Z" are feh arguments. "-F" opens the image in fullscreen mode, and "-Z" autozooms the image. Adding the -q flag (quiet) suppresses error-messages to the terminal when feh tries loading non-image files in current folder.

Also, this script could be expanded with: "else-if TERM = linux use feh instead". This would make it very versatile with midnight commander. (alas, I'm no bash-scripting guru).

Last edited by penguin (2011-02-09 14:25:35)

Offline

#19 2011-05-13 16:35:34

barto
Member
From: Budapest, Hungary
Registered: 2009-10-22
Posts: 88

Re: [SOLVED]Using feh to browse images

For the record, the required functionality can be achieved with the --start-at command line option of feh.

feh man page wrote:

feh --start-at ./foo.jpg .
             View all images in the current directory, starting with foo.jpg.
             All other images are still in the slideshow and can be viewed
             normally

     feh --start-at foo.jpg *
             Same as above

The exact (and working) string I have in ~/.mc/bindings is

feh --start-at ./%p

“First principle, Clarice. Simplicity” – Dr. Hannibal Lecter

Offline

#20 2011-06-18 20:49:41

Eiki
Member
Registered: 2009-10-08
Posts: 19

Re: [SOLVED]Using feh to browse images

So I'm trying out the --start-at solution again after initially being unsuccessful when it was first posted and still not able to get it to work how I want it to. Maybe someone can tell me what I'm doing wrong.

I've got it working fine on the command line as long as I'm in the directory where the image in question is located. I can't get it to work if I'm not working out of the same directory, neither by passing the relative nor the absolute path to the image. If I do, I get the error message:

feh ERROR: --start-at /path/to/foo.jpg: File not found in filelist

What I'd really like to get working though, is to be able to open the image straight from Thunar. I've tried using 'feh --start-at ./%f' as a custom command to open images but it does not work.

Using the script that's in the wiki now has worked just fine for me so far but if there's an easier way to get this functionality with feh, then I'll go with that.

Offline

#21 2011-06-19 00:22:42

barto
Member
From: Budapest, Hungary
Registered: 2009-10-22
Posts: 88

Re: [SOLVED]Using feh to browse images

The parameter %f returns the full path of the file, but feh doesn’t accept full path at the --start-at option. (That’s why I use %p, not %f in mc.) In thunar, try this custom command:

feh --start-at ./%n

“First principle, Clarice. Simplicity” – Dr. Hannibal Lecter

Offline

#22 2011-06-19 05:27:37

Eiki
Member
Registered: 2009-10-08
Posts: 19

Re: [SOLVED]Using feh to browse images

It works! Thanks very much.

Offline

#23 2012-04-25 17:18:26

bitcero
Member
Registered: 2011-11-03
Posts: 6

Re: [SOLVED]Using feh to browse images

Xyne wrote:

I've added it to the wiki. I've also made some changes to the script:

  • added comments

  • all arguments after the filepath are now passed to feh, e.g. "/path/to/script %f -F -Z"

Thanks very much,  maybe this little modification is useful if images are mixed with other files pdfs, txt, etc ?

#!/bin/bash

shopt -s nullglob

if [[ ! -f $1 ]]; then
    echo "$0: first argument is not a file" >&2
    exit 1
fi

file=$(basename -- "$1")
dir=$(dirname -- "$1")
arr=()
shift

cd -- "$dir"

frmt="*.jpg *.jpeg *.png *.bmp *.gif *.xcf *.ico *.tif *.tiff "
frmtall=${frmt}${frmt^^}

for i in $frmtall; do
    [[ -f $i ]] || continue
    arr+=("$i")
    [[ $i == $file ]] && c=$((${#arr[@]} - 1))
done

exec feh "$@" -- "${arr[@]:c}" "${arr[@]:0:c}"

Offline

#24 2012-04-26 06:41:58

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 6,856

Re: [SOLVED]Using feh to browse images

Please use code tags. And don't bump old threads. You could edit the wiki (if this still exists there, which I can't be bothered checking). In any case, closing for necrobump.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

Board footer

Powered by FluxBB