mirror of
https://github.com/mhinz/neovim-remote
synced 2024-11-11 13:10:34 +00:00
Cleaning up
This commit is contained in:
parent
fdcfedcec6
commit
dffbe22d1b
@ -25,46 +25,75 @@ THE SOFTWARE.
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import platform
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from neovim import attach
|
from neovim import attach
|
||||||
|
|
||||||
|
def parse_args():
|
||||||
|
usage = '{} [arguments]'.format(sys.argv[0])
|
||||||
|
desc = 'nvim wrapper that provides --remote and friends.'
|
||||||
|
epilog = 'Happy hacking!'
|
||||||
|
parser = argparse.ArgumentParser(usage=usage, description=desc, epilog=epilog)
|
||||||
|
|
||||||
|
parser.add_argument('--remote',
|
||||||
|
action='append',
|
||||||
|
metavar='<file>',
|
||||||
|
help='Edit <files> in a Neovim server.')
|
||||||
|
parser.add_argument('--remote-silent',
|
||||||
|
action='append',
|
||||||
|
metavar='<file>',
|
||||||
|
help='[Not implemented yet]')
|
||||||
|
parser.add_argument('--remote-wait',
|
||||||
|
action='append',
|
||||||
|
metavar='<file>',
|
||||||
|
help='Same as --remote.')
|
||||||
|
parser.add_argument('--remote-wait-silent',
|
||||||
|
action='append',
|
||||||
|
metavar='<file>',
|
||||||
|
help='[Not implemented yet]')
|
||||||
|
parser.add_argument('--remote-tab',
|
||||||
|
action='append',
|
||||||
|
metavar='<file>',
|
||||||
|
help='As --remote, but uses one tab page per file.')
|
||||||
|
parser.add_argument('--remote-send',
|
||||||
|
action='append',
|
||||||
|
metavar='<keys>',
|
||||||
|
help='Send <keys> to Neovim server.')
|
||||||
|
parser.add_argument('--remote-expr',
|
||||||
|
action='append',
|
||||||
|
metavar='<expr>',
|
||||||
|
help='Evaluate <expr> in Neovim server and print result.')
|
||||||
|
parser.add_argument('--terminal',
|
||||||
|
metavar='<termemu>',
|
||||||
|
help='Use the given terminal emulator to start a new server.')
|
||||||
|
|
||||||
|
return parser.parse_known_args()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
args, unused = parse_args()
|
||||||
parser.add_argument('--remote', action='append', help='Edit <files> in a Vim server if possible')
|
|
||||||
parser.add_argument('--remote-silent', help="Same, don't complain if there is no server")
|
|
||||||
parser.add_argument('--remote-wait', action='append', help='As --remote but wait for files to have been edited')
|
|
||||||
parser.add_argument('--remote-wait-silent', help="Same, don't complain if there is no server")
|
|
||||||
parser.add_argument('--remote-tab', action='append', help='As --remote but use tab page per file')
|
|
||||||
parser.add_argument('--remote-send', action='append', help='Send <keys> to a Vim server and exit')
|
|
||||||
parser.add_argument('--remote-expr', action='append', help='Evaluate <expr> in a Vim server and print result')
|
|
||||||
args, unused = parser.parse_known_args()
|
|
||||||
|
|
||||||
sockpath = os.environ.get('NVIM_LISTEN_ADDRESS')
|
sockpath = os.environ.get('NVIM_LISTEN_ADDRESS')
|
||||||
if sockpath is None:
|
if sockpath is None:
|
||||||
sockpath = '/tmp/nvimsocket'
|
sockpath = '/tmp/nvimsocket'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nvim = attach('socket', path='/tmp/nvimsocket')
|
nvim = attach('socket', path=sockpath)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("""Problem: Can't find unix socket: /tmp/nvimsocket
|
print("Can't find unix socket {}. Set NVIM_LISTEN_ADDRESS.".format(sockpath))
|
||||||
Solution: Start a new server: NVIM_LISTEN_ADDRESS=/tmp/nvimsocket nvim""")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if args.remote:
|
if args.remote:
|
||||||
for fname in args.remote:
|
for fname in args.remote:
|
||||||
nvim.command('edit {}'.format(fname))
|
nvim.command('edit {}'.format(fname))
|
||||||
|
|
||||||
# Not implemented yet.
|
|
||||||
if args.remote_silent:
|
if args.remote_silent:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Hint: Same as --remote.
|
|
||||||
if args.remote_wait:
|
if args.remote_wait:
|
||||||
for fname in args.remote_wait:
|
for fname in args.remote_wait:
|
||||||
nvim.command('edit {}'.format(fname))
|
nvim.command('edit {}'.format(fname))
|
||||||
|
|
||||||
# Not implemented yet.
|
|
||||||
if args.remote_wait_silent:
|
if args.remote_wait_silent:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user