Last active
June 20, 2021 14:42
-
-
Save kraftwerk28/e059ecef3561bd24ecc0c25f7ea0ca4d to your computer and use it in GitHub Desktop.
Open links with documentation in neovim instead of browser
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 characters
| -- 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 |
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 characters
| [Desktop Entry] | |
| Type=Application | |
| Name=Opennvimlink | |
| Exec=path/to/script.py %u | |
| Terminal=false |
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 characters
| #!/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