summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xnvim-setup.sh20
-rwxr-xr-xnvimctl.py71
2 files changed, 91 insertions, 0 deletions
diff --git a/nvim-setup.sh b/nvim-setup.sh
new file mode 100755
index 0000000..cd8ccc2
--- /dev/null
+++ b/nvim-setup.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+set -e
+
+plugged_dir="$HOME/.local/share/nvim/plugged"
+mkdir -p "$plugged_dir"
+cd "$plugged_dir"
+
+git clone git@git.josher.dev:config.vim.git config.vim
+
+mkdir -p "$HOME/.config/"
+cd "$HOME/.config/"
+
+ln -sf "$plugged_dir/config.vim" nvim
+
+curl -fLo "$HOME/.local/share/nvim/site/autoload/plug.vim" --create-dirs \
+ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
+
+ln -sf "$HOME/.config/nvim/run_vim.py" "$HOME/.local/bin/vim"
+ln -sf "$HOME/.config/nvim/nvimctl.py" "$HOME/.local/bin/nvimctl"
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()