neovim-remote icon indicating copy to clipboard operation
neovim-remote copied to clipboard

Specify pid instead of socket

Open ModProg opened this issue 3 years ago • 3 comments

Is it possible to select the nvim instance by PID instead of socket?

I want to query the current state of an instance to decide whether I need to ask before closing a tab in my terminal, but I only have the PID of the nvim process in question.

Is there a convinient way to run the evaluation on the nvim instance with that PID. I was thinking something like:

nvr --process 123456 --remote-expr "getbufinfo({'bufmodified': 1})"

ModProg avatar Jan 31 '22 22:01 ModProg

You could use lsof -p {pid} to find out what files your process has open, and select the socket from that list.

KillTheMule avatar Feb 01 '22 19:02 KillTheMule

Alright, I'll use lsof -p 133249 | awk '{print $9}' | grep /tmp/nvim for now. Maybe not ideal but should probably be reliable

ModProg avatar Feb 02 '22 16:02 ModProg

on my machine, as long as I don't set the NVIM_LISTEN_ADDRESS environment variable (which, while supported by nvr, is deprecated in nvim, but still has an effect on the socket name), the PID is added to the socket, e.g.

$ nvr --serverlist
/run/user/1000/nvim.878819.0

so it is possible to do this if you know the PID:

$ PID=878819
$ nvr --servername "${XDG_RUNTIME_DIR}/nvim.${PID}.0" ...

(the .0 at the end is a counter, but I believe it is incremented only if the same process is serving on multiple sockets)

joshbode avatar Sep 27 '22 01:09 joshbode