-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvim-wt-defx.py
63 lines (47 loc) · 1.59 KB
/
nvim-wt-defx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
import neovim
import subprocess
import re
from time import sleep
def main():
oyo = {}
cnt = 0
hoge = subprocess.Popen("pipelist64.exe", stdout=subprocess.PIPE, text=True).stdout.readlines()
print("Searching Neovim instances...")
for are in hoge:
if re.search(r'nvim', are):
num0 = re.sub(r'^nvim-([0-9]*)-[0-9].*$', r'\1', are).strip('\n')
print("\t" + are, end="")
oyo[num0] = False
cnt += 1
print("Starting new Neovim instance.")
subprocess.Popen("C:\\Users\\masa300V\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -p \"Neovim\"")
sleep(3)
hoge = subprocess.Popen("pipelist64.exe", stdout=subprocess.PIPE, text=True).stdout.readlines()
for are in hoge:
if re.search(r'nvim', are):
num = re.sub(r'^nvim-([0-9]*)-[0-9].*$', r'\1', are).strip('\n')
if oyo.get(num, True):
print('Using new nvim %s.' % num)
servername = "\\\\.\\pipe\\nvim-" + num + "-0"
print(servername)
try:
nvim = neovim.attach("socket", path=servername)
except Exception:
print("Neovim not found")
return 1
if len(sys.argv) > 2:
return
if len(sys.argv) == 1:
path = os.path.abspath(os.getcwd())
if len(sys.argv) == 2:
path = os.path.abspath(sys.argv[1])
print(path)
path2 = re.sub(r' ', r'\ ', path.replace(os.path.sep, '/'))
print(':Defx %s' % path2)
nvim.command(':Defx %s' % path2)
nvim.close()
if __name__ == "__main__":
ret = main()
sys.exit(ret)