Last active
April 20, 2016 16:16
-
-
Save dmerejkowsky/3fcb8473588f66a8339483a50e299a8b to your computer and use it in GitHub Desktop.
Autorefresh chromium from a neovim key binding
This file contains 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 | |
""" 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