aboutsummarylogtreecommitdiffstats
path: root/nvim-wrapper
blob: 6ea768294ae8be0f91664f82ff7810befa4a81f8 (plain)
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
#!/usr/bin/env python3

"""Run nvim inside gnome-terminal"""

import sys
import os
import subprocess
import dbus
from time import time

SERVER_CMD = [
    '/usr/lib/gnome-terminal/gnome-terminal-server',
    '--app-id=org.neovim',
]
TERM_CMD = [
    'gnome-terminal',
    '--name=Neovim',
    '--hide-menubar',
    '--geometry=90x60',
    '--app-id=org.neovim',
    '--class=neovim',
    '-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('org.neovim'):
        subprocess.Popen(SERVER_CMD)

    # wait until the name is registered, or 2 seconds pass (when launching from
    # cold cache it might more time)
    timeout = time() + 2
    while not session_bus.name_has_owner('org.neovim') and time() <= timeout:
        pass
    # launch nvim in a gnome-terminal instance
    if session_bus.name_has_owner('org.neovim'):
        with open(os.devnull, 'wb') as fnull:
            subprocess.Popen(TERM_CMD + sys.argv[1:],
                             stdout=fnull,
                             stderr=fnull)
                             # preexec_fn=os.setpgrp)

if __name__ == '__main__':
    main()