Tuesday, March 31, 2020

Re: detaching instance of a process ran in Vim's command mode

On 31Mar2020 12:40, Manas Gupta <manas18244@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 <cs@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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200331083503.GA38509%40cskk.homeip.net.

No comments:

Post a Comment