Skip to content

Instantly share code, notes, and snippets.

@aliev
Created April 18, 2015 07:01
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 aliev/ab24f3db9f89bfb86917 to your computer and use it in GitHub Desktop.
Save aliev/ab24f3db9f89bfb86917 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
from __future__ import print_function
import pathlib
import argparse
import os
from neovim import attach
def main():
parser = argparse.ArgumentParser(
description="Opens the file in the current running neovim session"
)
parser.add_argument(
'file',
type=pathlib.Path,
help='The name of the file you want to open in neovim'
)
args = parser.parse_args()
file_path = args.file.absolute()
if file_path.is_dir():
file_path = str(file_path) + '/'
listen_address = os.environ.get('NVIM_LISTEN_ADDRESS')
try:
nvim = attach('socket', path=listen_address)
nvim.command('e {file_path}'.format(file_path=file_path))
except ValueError:
print("Please run neovim before opening the file")
return -1
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment