Suppose I have a file images.txt which contains for example


Then I pipe the images.txt to sxiv and I want that the thumbnail view reflects the changes immediately. I tried this one:

watch -n 0.1 'cat images.txt | sxiv -i -t'

But if I change the images.txt and save it (for example by adding or removing an image-filename), the thumbnail view in sxiv doesn't update.

I guess that there is something wrong with my pipe construction. What would be the correct way to do this?

  • Maybe add a -p to tell sxiv not to cache the images? It would make a lot more sense to only run sxiv when something changes rather than 10 times a second. – icarus Dec 31 '18 at 23:04
  • Ah, I just noticed that I have to close the sxiv window to update the changes in the images.txt file (then immediately a new window pops up with the updated content) if I use my pipe construct, but that's not exactly what I wanted. – student Dec 31 '18 at 23:22

Your existing construction will attempt to run cat images.txt | sxiv -i -t every tenth of a second. If sxiv takes longer than that to do whatever it does, things could get quite messy. You might be better off looking at a hash of a checksum of all of the images:

$ md5sum *.jpg | md5sum
4a009e73fb133d2d103dd2e65ef8c605  -

This takes a hash of all of the .jpg files, and makes a hash of that. This means that the sur-checksum will change if any of the images are changes, as well as if any are added or removed.

So we can do something like this:

old_checksum="$(md5sum *.jpg | md5sum)"
while /bin/true; do
    new_checksum="$(md5sum *.jpg | md5sum)"
    if [[ "$new_checksum" != "$old_checksum" ]]; then
        find . -maxdepth 1 -name \*.jpg -print0 | xargs -0 sxiv -i -t
    sleep 1

Anytime anything changes, take a note of the new checksum, and re-run sxiv.

If you still want to keep your catalog of .jpg files in images.txt, this can be easily modified to use the contents of that file for creating the checksum and for providing arguments to xargs in lieu of find.

  • Thanks. Yes indeed I want to keep the "catalog" in "images.txt". The file will be auto updated in another step. How would your solution look like using "images.txt"? Just calculate the md5sum of images.txt and replace the find command with cat images.txt? – student Dec 31 '18 at 23:25
  • I think you need a killall sxiv before the find line to prevent that a new instance of sxiv is started and also a & after -t? – student Dec 31 '18 at 23:34
  • I don't use a & to ensure that only one instance of find and therefore only one instance of sxiv is ever running at a time, which means a kill should not be needed. – DopeGhoti Jan 1 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.