diff --git a/docs/shell-integration.rst b/docs/shell-integration.rst index e24c09c04..c729a2326 100644 --- a/docs/shell-integration.rst +++ b/docs/shell-integration.rst @@ -171,7 +171,7 @@ code used for each shell below: .. tab:: bash - .. literalinclude:: ../shell-integration/kitty.bash + .. literalinclude:: ../shell-integration/bash/kitty.bash :language: bash .. raw:: html @@ -201,16 +201,16 @@ Then in your shell's rc file, add the lines: .. code-block:: sh - if [[ ! -z "$KITTY_INSTALLATION_DIR" ]]; then + if test -n "$KITTY_INSTALLATION_DIR"; then export KITTY_SHELL_INTEGRATION="enabled" - source "$KITTY_INSTALLATION_DIR/shell-integration/kitty.bash" + source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash" fi .. tab:: zsh .. code-block:: sh - if [[ ! -z "$KITTY_INSTALLATION_DIR" ]]; then + if test -n "$KITTY_INSTALLATION_DIR"; then export KITTY_SHELL_INTEGRATION="enabled" source "$KITTY_INSTALLATION_DIR/shell-integration/zsh/kitty.zsh" fi diff --git a/kitty/shell_integration.py b/kitty/shell_integration.py index 5d96ed5ab..dcadc0157 100644 --- a/kitty/shell_integration.py +++ b/kitty/shell_integration.py @@ -13,7 +13,7 @@ from .utils import log_error, resolved_shell posix_template = ''' # BEGIN_KITTY_SHELL_INTEGRATION -if test -e {path}; then source {path}; fi +if test -n "$KITTY_INSTALLATION_DIR" -a -e "$KITTY_INSTALLATION_DIR/{path}"; then source "$KITTY_INSTALLATION_DIR/{path}"; fi # END_KITTY_SHELL_INTEGRATION ''' @@ -35,11 +35,7 @@ def setup_integration(shell_name: str, rc_path: str, template: str = posix_templ import re rc_path = os.path.realpath(rc_path) rc = safe_read(rc_path) - home = os.path.expanduser('~') + '/' - path = os.path.join(shell_integration_dir, f'kitty.{shell_name}') - if path.startswith(home): - path = '$HOME/' + path[len(home):] - integration = template.format(path=f'"{path}"') + integration = template.format(path=f"shell-integration/{shell_name}/kitty.{shell_name}") newrc = re.sub( r'^# BEGIN_KITTY_SHELL_INTEGRATION.+?^# END_KITTY_SHELL_INTEGRATION', '', rc, flags=re.DOTALL | re.MULTILINE) diff --git a/shell-integration/kitty.bash b/shell-integration/bash/kitty.bash similarity index 100% rename from shell-integration/kitty.bash rename to shell-integration/bash/kitty.bash