#!/usr/bin/env python3
# vim: ts=4 sw=4 sts=4 et ai

import os
import sys

VIM = ('/usr/bin/nvim', '/opt/homebrew/bin/nvim', '/usr/local/bin/nvim', '/usr/bin/vim', '/usr/bin/vi')
for executable in VIM:
  if os.path.exists(executable):
    break
else:
  sys.exit(1)

args = []
for a in sys.argv[1:]:
    if ':' in a:
        filename, lineno = a.split(':')[:2]
        if os.path.exists(filename):
            args.append(f'+{lineno}')
            args.append(filename)
            continue
    args.append(a)

cmd = (executable, ) + tuple(args)
print(f'execute {cmd}')
os.execlp(cmd[0], *cmd)
