This commit is contained in:
Kovid Goyal 2022-01-27 11:29:33 +05:30
parent 4397e60206
commit 9f2be8b696
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -11,10 +11,10 @@ from .config import atomic_save
from .constants import shell_integration_dir
from .utils import log_error, resolved_shell
posix_template = '''
posix_template = '''\
# BEGIN_KITTY_SHELL_INTEGRATION
if test -n "$KITTY_INSTALLATION_DIR" -a -e "$KITTY_INSTALLATION_DIR/{path}"; then source "$KITTY_INSTALLATION_DIR/{path}"; fi
# END_KITTY_SHELL_INTEGRATION
# END_KITTY_SHELL_INTEGRATION\
'''
@ -36,9 +36,10 @@ def setup_integration(shell_name: str, rc_path: str, template: str = posix_templ
rc_path = os.path.realpath(rc_path)
rc = safe_read(rc_path)
integration = template.format(path=f"shell-integration/{shell_name}/kitty.{shell_name}")
newrc = re.sub(
newrc, num_subs = re.subn(
r'^# BEGIN_KITTY_SHELL_INTEGRATION.+?^# END_KITTY_SHELL_INTEGRATION',
'', rc, flags=re.DOTALL | re.MULTILINE)
integration, rc, flags=re.DOTALL | re.MULTILINE)
if num_subs < 1:
newrc = newrc.rstrip() + '\n\n' + integration
if newrc != rc:
atomic_write(rc_path, newrc)