#!/usr/bin/env python3
from pynvim import attach
import os, sys

args = sys.argv[1:]
if not args:
    print("Usage: {} <filename> ...".format(sys.argv[0]))
    sys.exit(1)

addr = os.environ["NVIM"]
if not addr:
    # TODO: Open a new nvim instance if no addr
    sys.exit(2)

nvim = attach("socket", path=addr)
print(nvim.eval("fnamemodify(bufname(winbufnr(%d)), \":p\")" % int(args[0])))
