On 31Mar2020 12:40, Manas Gupta <manas18...@iiitd.ac.in> wrote:
I want to run an instance of Okular for every markdown file using bang (!)
in Vim's command mode (like this :!okular % &). And I leave the Okular
instance open on the side. But when I make changes in the file and save it,
Okular also makes the changes in its instance which I don't want.

So this means that Okular monitors the contents of the filename why you gave it.

If that is true, this means that Okular needs to be given a copy of your file, not the original (because you want to overwrite the original without disturbing Okular).

On that basis I would write a script which does 3 things:
- take a copy of the filename handed to it
- dispatches Okular against the copy
- after the instance of Okular exits, remove the copy file

Something like:

 #!/bin/sh
 set -ue
 cmd=$( basename "$0" )
 [ $# = 1 ] || { echo "Usage: $cmd filename" >&2; exit 2; }
 filename=$1
 fbase=$( basename "$filename" )
 tmpf=${TMPDIR:-/tmp}/$cmd.$$.$fbase
 ( okular "$tmpf"
   rm "$tmpf"
 ) >/dev/null &

which makes the copy and runs an asynchronous okular with cleanup.

I also added & at the end of shell command in hope that it will detach that
process but that doesn't seem to work as I want.

No, because your problem is stopping Okular watching the file you're editing, hence the copy above.

The "&" isn't magic - it just says "continue without waiting for this command to finish".

Cheers,
Cameron Simpson <c...@cskk.id.au>

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/20200331083503.GA38509%40cskk.homeip.net.

Reply via email to