Skip to content

Instantly share code, notes, and snippets.

@kraftwerk28
Last active June 20, 2021 14:42
Show Gist options
  • Select an option

  • Save kraftwerk28/e059ecef3561bd24ecc0c25f7ea0ca4d to your computer and use it in GitHub Desktop.

Select an option

Save kraftwerk28/e059ecef3561bd24ecc0c25f7ea0ca4d to your computer and use it in GitHub Desktop.
Open links with documentation in neovim instead of browser
-- Put this somewhere in init.lua
if vim.fn.has"unix" then
-- Listen for :help call from .desktop python script
pcall(vim.fn.serverstart, "localhost:" .. (vim.env.NVIM_LISTEN_PORT or 6969))
end
#!/usr/bin/env python
import os
import sys
from urllib.parse import unquote, urlparse
from pynvim import tcp_session
parsed = urlparse(sys.argv[1])
try:
if parsed.hostname not in ("vimhelp.org", "neovim.io"):
raise Exception()
topic = unquote(parsed.fragment)
session = tcp_session("localhost", os.getenv("NVIM_LISTEN_PORT", "6969"))
session.request("nvim_command", f"help {topic}")
session.request("nvim_command", "wincmd L")
session.close()
# Display a notification from kitty; since I use wayland and there isn't
# any way to manually raise the window, like in wmctrl
os.system(f"notify-send -a kitty \"neovim: {topic}\"")
except:
os.system(f"firefox {sys.argv[1]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment