On 31Mar2020 12:40, Manas Gupta <
manas...@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>