diff options
author | Josh Rahm <rahm@google.com> | 2023-01-25 23:07:14 +0000 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2023-01-25 23:07:43 +0000 |
commit | b650f30b56edf5a0be062891939e855f5044d990 (patch) | |
tree | 064113175b97295824cf1a155d648ce9baeed29d /nvimctl.py | |
parent | 0a520e2f4f4bbf9e70307f850e33b364913558d6 (diff) | |
download | config.vim-b650f30b56edf5a0be062891939e855f5044d990.tar.gz config.vim-b650f30b56edf5a0be062891939e855f5044d990.tar.bz2 config.vim-b650f30b56edf5a0be062891939e855f5044d990.zip |
Add nvim-setup.sh and nvimctl.py
Diffstat (limited to 'nvimctl.py')
-rwxr-xr-x | nvimctl.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/nvimctl.py b/nvimctl.py new file mode 100755 index 0000000..42e083a --- /dev/null +++ b/nvimctl.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +import os +import sys +import neovim + +try: + nvim_socket = os.environ["NVIM"] +except KeyError: + sys.stderr.write("Not inside Neovim terminal") + sys.exit(1) + +nvim = neovim.attach('socket', path=nvim_socket) + + +class GetReg: + def name(self): + return "getreg" + + def usage(self): + return "[register]" + + def descr(self): + return "Prints the contents of a Neovim register to stdout." + + def run(self, args): + register = args[0] + print(nvim.funcs.getreg(register)) + + +class PutReg: + def name(self): + return "setreg" + + def usage(self): + return "[register]" + + def descr(self): + return "Puts the contents of stdin into a Neovim register." + + def run(self, args): + register = args[0] + lines = sys.stdin.read().splitlines() + + if len(lines) == 1: + lines = lines[0] + + nvim.funcs.setreg(register, lines) + + +def print_help(): + sys.stderr.write("USAGE %s <command> [args...]\n" % sys.argv[0]) + sys.stderr.write("commands:\n") + for c in commands: + sys.stderr.write("\t%s: %s\n" % (c.name(), c.descr())) + + +commands = [GetReg(), PutReg()] + +if len(sys.argv) < 2: + print_help() + sys.exit(1) + +cmd = sys.argv[1] +args = sys.argv[2:] +for c in commands: + if cmd == c.name(): + sys.exit(c.run(args) or 0) + +sys.stderr.write("Unknown command %s\n" % cmd) +print_help() |