Created
April 18, 2015 07:01
-
-
Save aliev/ab24f3db9f89bfb86917 to your computer and use it in GitHub Desktop.
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/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