Add a --detach option

Allows kitty to detach itself from the controlling terminal. Useful
when launching kitty from a GUI environment with broken stdout/stderr or
when launching from a terminal that you want to close later without
affecting the launched kitty instance.
This commit is contained in:
Kovid Goyal
2017-08-03 22:35:47 +05:30
parent 9d62d087e0
commit ed50595aca
3 changed files with 36 additions and 2 deletions
+12 -1
View File
@@ -14,7 +14,7 @@ from functools import lru_cache
from time import monotonic
from .constants import isosx
from .fast_data_types import glfw_get_physical_dpi, wcwidth as wcwidth_impl
from .fast_data_types import glfw_get_physical_dpi, wcwidth as wcwidth_impl, redirect_std_streams
from .rgb import Color, to_color
@@ -215,3 +215,14 @@ def open_url(url, program='default'):
cmd = shlex.split(program)
cmd.append(url)
subprocess.Popen(cmd).wait()
def detach(fork=True, setsid=True, redirect=True):
if fork:
# Detach from the controlling process.
if os.fork() != 0:
raise SystemExit(0)
if setsid:
os.setsid()
if redirect:
redirect_std_streams(os.devnull)