savannah-hackers-public
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Savannah-hackers-public] sxiv script for ranger


From: Jason Beard
Subject: [Savannah-hackers-public] sxiv script for ranger
Date: Tue, 28 Jan 2014 13:53:10 +0000

Hi,

I found your script for sxiv with ranger through the arch wiki. It is brilliant!  However I've had issues with large folders (~3000 pictures) where sxiv shows fewer files.  When you quit, it shows the next batch (then the next...).  This seems to be the result of xarg limiting the length passed. Which I'm not sure is avoidable.

I'm a bit of a beginner at scripting, but I've got something working (shown below) and learned a bit by having a stab.  I had to switch to a list on separate lines (not a problem as my files don't have line-breaks in them).  As noted in your comments this probably isn't portable, but for me it works and is faster on large directories as I only have to call listfiles once.

I'm not confident enough to post this up (as I've probably broken lots of things through inexperience and it's all your work), so I wondered if you might make a note about when the other script fails (it took me ages to work out why) and maybe provide a simpler (if less portable) version.

Also note that the line [ "$1" == '--' ] && shift seems to be bash, not sh and throws an error.

Thanks again for the script.


Regards

Jason




if [ $# -eq 0 ]; then
    echo "Usage: ${0##*/} PICTURES"
    exit
fi

[ "$1" = '--' ] && shift  #I changed this from == to = as == is bash-ism

abspath () {
    case "$1" in
        /*) printf "%s\n" "$1";;
        *)  printf "%s\n" "$PWD/$1";;
    esac
}

listfiles () {
    find -L "$(dirname "$target")" -maxdepth 1 -type f \
    -iregex '.*\(jpe?g\|bmp\|png\|gif\)$' | sort -V #natural sort
}

target="$(abspath "$1")"
mylist="$(listfiles)"

count="$(echo "$mylist" | grep -m 1 -nF "$target" | cut -d: -f1)"

if [ -n "$count" ]; then
    echo "$mylist" | sxiv -n "$count" -i
else
    sxiv -- "$@" # fallback
fi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]