From f430c03ff3e094fd917f10a955160884579aa143 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Tue, 19 Aug 2025 10:35:05 -0400 Subject: [PATCH 1/3] zsh: add tests for setupZsh --- src/termio/shell_integration.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/termio/shell_integration.zig b/src/termio/shell_integration.zig index 438c2a0ea..30519b6e2 100644 --- a/src/termio/shell_integration.zig +++ b/src/termio/shell_integration.zig @@ -670,3 +670,27 @@ fn setupZsh( ); try env.put("ZDOTDIR", integ_dir); } + +test "zsh" { + const testing = std.testing; + + var env = EnvMap.init(testing.allocator); + defer env.deinit(); + + try setupZsh(".", &env); + try testing.expectEqualStrings("./shell-integration/zsh", env.get("ZDOTDIR").?); + try testing.expect(env.get("GHOSTTY_ZSH_ZDOTDIR") == null); +} + +test "zsh: ZDOTDIR" { + const testing = std.testing; + + var env = EnvMap.init(testing.allocator); + defer env.deinit(); + + try env.put("ZDOTDIR", "$HOME/.config/zsh"); + + try setupZsh(".", &env); + try testing.expectEqualStrings("./shell-integration/zsh", env.get("ZDOTDIR").?); + try testing.expectEqualStrings("$HOME/.config/zsh", env.get("GHOSTTY_ZSH_ZDOTDIR").?); +} From e8a60a375c2902caa4727aafa3cc61345f4085a3 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Tue, 19 Aug 2025 10:36:26 -0400 Subject: [PATCH 2/3] zsh: unset _ghostty_file in the early exit path If we're running a too-old version of zsh, we exit early. This skipped the _ghostty_file cleanup path below. --- src/shell-integration/zsh/.zshenv | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shell-integration/zsh/.zshenv b/src/shell-integration/zsh/.zshenv index 7fbfad659..3941e0c30 100644 --- a/src/shell-integration/zsh/.zshenv +++ b/src/shell-integration/zsh/.zshenv @@ -45,6 +45,7 @@ fi 'builtin' 'autoload' '--' 'is-at-least' 'is-at-least' "5.1" || { builtin echo "ZSH ${ZSH_VERSION} is too old for ghostty shell integration" > /dev/stderr + 'builtin' 'unset' '_ghostty_file' return } # ${(%):-%x} is the path to the current file. From 8300512a9118b7757958b95703914998b5111f9b Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Tue, 19 Aug 2025 10:39:09 -0400 Subject: [PATCH 3/3] zsh: clarify that an unset ZDOTDIR defaults to HOME This fixes the incorrect comment and uses $HOME (rather than ~) to be a little bit more explicit. Also, our script is named ghostty-integration, not ghostty.zsh, so update that part of the comment, too. --- src/shell-integration/zsh/.zshenv | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/shell-integration/zsh/.zshenv b/src/shell-integration/zsh/.zshenv index 3941e0c30..3332b1c1f 100644 --- a/src/shell-integration/zsh/.zshenv +++ b/src/shell-integration/zsh/.zshenv @@ -29,14 +29,15 @@ fi # Use try-always to have the right error code. { - # Zsh treats empty $ZDOTDIR as if it was "/". We do the same. + # Zsh treats unset ZDOTDIR as if it was HOME. We do the same. # - # Source the user's zshenv before sourcing ghostty.zsh because the former - # might set fpath and other things without which ghostty.zsh won't work. + # Source the user's .zshenv before sourcing ghostty-integration because the + # former might set fpath and other things without which ghostty-integration + # won't work. # # Use typeset in case we are in a function with warn_create_global in # effect. Unlikely but better safe than sorry. - 'builtin' 'typeset' _ghostty_file=${ZDOTDIR-~}"/.zshenv" + 'builtin' 'typeset' _ghostty_file=${ZDOTDIR-$HOME}"/.zshenv" # Zsh ignores unreadable rc files. We do the same. # Zsh ignores rc files that are directories, and so does source. [[ ! -r "$_ghostty_file" ]] || 'builtin' 'source' '--' "$_ghostty_file"