Forked from mousebyte/coc-discord-rpc-wsl-passthrough.md
Created
August 22, 2021 19:31
Revisions
-
mousebyte revised this gist
Mar 29, 2021 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,8 @@ I use fish, so my alias looks something like this: ```sh function nvim pidof socat > /dev/null; or socat UNIX-LISTEN:/tmp/discord-ipc-0,fork \ EXEC:"npiperelay.exe //./pipe/discord-ipc-0"& command nvim $argv end ``` @@ -50,8 +51,8 @@ nvim () { if ! $? -eq 0; then socat UNIX-LISTEN:/tmp/discord-ipc-0,fork \ EXEC:"npiperelay.exe //./pipe/discord-ipc-0"& fi command nvim "$@" } ``` -
mousebyte created this gist
Mar 29, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ # Using coc-discord-rpc on WSL You can use [npiperelay][] to let coc-discord-rpc connect to a Discord instance running on the host Windows operating system. It requires modifying the extension a bit, but it's relatively painless. This guide assumes you have [coc.nvim][] and [coc-discord-rpc][] already installed. ## Get npiperelay and socat To build npiperelay, you'll need [Go][]. Grab the `golang` package from your favorite package manager and follow the instructions on the [npiperelay][] repo. You'll also need to install `socat` if it doesn't come with your distribution. ## Modify the coc-discord-rpc extension To locate the Discord IPC socket, the [coc-discord-rpc][] extension looks in the subdirectory of `/tmp/` created for NeoVim when it starts. Discord, however, puts its IPC in the root of `/tmp/`, not a subdirectory. And since we will be starting `socat` before NeoVim, we won't be able to put the forwarded socket in its subdirectory. We have to modify the extension to look in the correct directory. Open the main source file, which should be located at `~/.config/coc/extensions/node_modules/coc-discord-rpc/lib/index.js`. Search for the function named `getIPCPath`. This function contains a line that sets the path prefix for the IPC socket. It should look something like this: ```js const prefix = XDG_RUNTIME_DIR || TMPDIR || TMP || TEMP || '/tmp'; ``` Change that line to the following: ```js const prefix = '/tmp'; ``` ## Aliasing nvim Now that the extension is looking in the right place, we have to put an actual IPC socket there. To do so, we need to launch `socat` before NeoVim to forward the Discord IPC named pipe from Windows. You can do this by creating an alias for `nvim` that checks if `socat` is running and launches it in the background if it isn't. I use fish, so my alias looks something like this: ```sh function nvim pidof socat > /dev/null; or socat UNIX-LISTEN:/tmp/discord-ipc-0,fork EXEC:"npiperelay.exe //./pipe/discord-ipc-0"& command nvim $argv end ``` Or in bash: ```sh nvim () { pidof socat > /dev/null 2>&1 if ! $? -eq 0; then socat UNIX-LISTEN:/tmp/discord-ipc-0,fork \ EXEC:"npiperelay.exe //./pipe/discord-ipc-0"& command nvim "$@" fi } ``` And that's it! Running `nvim` from your shell of choice should now allow it to connect to the Discord IPC pipe on your host Windows system (as long as you have Discord running, of course). ***Note:*** Using the `fork` option to `socat` ensures that you won't get connection errors when running multiple instances of NeoVim. However, only the first opened instance will be able to provide rich presence. If you decide to try to modify coc-discord-rpc to support multiple instances of NeoVim, I'd definitely love to hear about it. [npiperelay]: https://github.com/jstarks/npiperelay/ [coc.nvim]: https://github.com/neoclide/coc.nvim/ [coc-discord-rpc]: https://github.com/LeonardSSH/coc-discordrpc/ [Go]: golang.org