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
63
64
65
66
67
68
69
|
#!/usr/bin/env python3
"""Run nvim inside gnome-terminal"""
import sys
import os
import subprocess
import dbus
from time import time
APP_ID = 'org.neovim'
CLASS = 'neovim'
NAME = 'Neovim'
def find_terminal_server():
candidates = list(filter(os.path.exists, \
('/usr/lib/gnome-terminal/gnome-terminal-server', # arch et al
'/usr/libexec/gnome-terminal-server'))) # fedora 22
if len(candidates) > 0:
return candidates[0]
else:
print("nvim-wrapper needs gnome-terminal-server, but it wasn't found.")
sys.exit()
SERVER_CMD = [
find_terminal_server(),
'--app-id', APP_ID,
'--class', CLASS,
'--name', NAME,
]
TERM_CMD = [
'gnome-terminal',
'--app-id', APP_ID,
'--class', CLASS,
'--name', NAME,
'--hide-menubar',
'-x',
'nvim',
]
def main():
"""Run nvim inside gnome-terminal"""
session_bus = dbus.SessionBus()
# launch the terminal server with a custom app-id
# and window class (so the .desktop file gets associated)
if not session_bus.name_has_owner(APP_ID):
subprocess.Popen(SERVER_CMD)
# wait until the name is registered, or 2 seconds pass (when launching from
# cold cache it might take more time)
timeout = time() + 2
while not session_bus.name_has_owner(APP_ID) and time() <= timeout:
pass
# launch nvim in a gnome-terminal instance
if session_bus.name_has_owner(APP_ID):
env = os.environ.copy()
env['NVIM_TUI_ENABLE_CURSOR_SHAPE'] = '1'
env['NVIM_TUI_ENABLE_TRUE_COLOR'] = '1'
with open(os.devnull, 'wb') as fnull:
subprocess.Popen(TERM_CMD + sys.argv[1:],
stdout=fnull,
stderr=fnull,
env=env)
if __name__ == '__main__':
main()
|