mhinz / neovim-remote

:ok_hand: Support for --remote and friends.
MIT License
1.75k stars 83 forks source link

Specify pid instead of socket #172

Open ModProg opened 2 years ago

ModProg commented 2 years ago

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})"
KillTheMule commented 2 years ago

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

ModProg commented 2 years ago

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

joshbode commented 2 years ago

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)