Skip to content

Instantly share code, notes, and snippets.

@dmerejkowsky
Last active April 20, 2016 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmerejkowsky/3fcb8473588f66a8339483a50e299a8b to your computer and use it in GitHub Desktop.
Save dmerejkowsky/3fcb8473588f66a8339483a50e299a8b to your computer and use it in GitHub Desktop.
Autorefresh chromium from a neovim key binding
#!/usr/bin/env python
""" Usage:
* Start neovim with NVIM_LISTEN_ADDRESS=/tmp/neovim
* Install selenium and neovim Python packages from pypi
* Run autorefresh URL
* In neovim, map a kep to send the event:
nnoremap ,m :w<cr>:call rpcnotify(0, "refresh")<cr>
* Enjoy :)
"""
import sys
from selenium import webdriver
import neovim
def main():
url = sys.argv[1]
driver = webdriver.Chrome()
driver.get(url)
vim = neovim.attach("socket", path="/tmp/neovim")
vim.subscribe("refresh")
try:
while True:
_ = vim.next_message()
driver.refresh()
except:
# Pokemon : gotta catch 'em all !
pass
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment