pqiv icon indicating copy to clipboard operation
pqiv copied to clipboard

Open new images in an existing instance

Open jarun opened this issue 6 years ago • 7 comments

This is probably more of a feature request than a defect. Is it possible to open a new image in an existing instance of pqiv? I am trying to achieve a workflow where:

  1. open an image in pqiv in the background
  2. open a new image in the above instance of pqiv instead of a new instance/window

jarun avatar Mar 21 '19 17:03 jarun

You can do that by adding a wrapper script and using --actions-from-stdin if you need a quick workaround.

phillipberndt avatar Mar 21 '19 17:03 phillipberndt

Can you please share the steps?

I added the following in a wrapper:

#!/usr/bin/env sh

pqiv --actions-from-stdin

Now if I start the script in the bg it quits immediately.

jarun avatar Mar 22 '19 00:03 jarun

I'm thinking something like

#!/bin/sh
#
mkfifo _pqiv_fifo
cleanup() { rm _pqiv_fifo; }
trap cleanup EXIT
(while true; do cat _pqiv_fifo; done) | pqiv -r

for the server and for the client

#!/bin/sh
#

for FN in "$@"; do
	echo "$FN" > _pqiv_fifo
done

Combine this into a single script that automatically detects whether to fork a server and you've got your single-session wrapper :)

phillipberndt avatar Mar 22 '19 22:03 phillipberndt

Thanks!

jarun avatar Mar 22 '19 22:03 jarun

I am looking for a simple way to integrate pqiv and nnn in such a way that one can traverse through image files in nnn and those could be viewed in pqiv.

Thinking of the following flow:

  • user presses a keybind in nnn to start pqiv in listening mode (nnn calls pqiv with a specific option to do this)
  • when he traverses through the files/or presses Enter, nnn calls pqiv with a specific option and the file name so the file is opened in the existing instance of pqiv

The integration should be transparent to the user and without the need of any additional script. To be more specific, I was looking for an image viewer with a single instance mode so newly opened files are opened in the current instance of the viewer.

I am not sure how hard it is to achieve this. But if it works that would be great.

jarun avatar Mar 23 '19 01:03 jarun

If nnn will drive this, why not just have it own the process and control it? ranger does it this way.

I have an advanced version of ranger's integration at work which does exactly what you want, I'll share the code next week, you should be able to copy the ideas quite easily.

phillipberndt avatar Mar 23 '19 06:03 phillipberndt

sure!

jarun avatar Mar 23 '19 06:03 jarun