zsh: minor shell integration improvements (#8281)

- test `setupZsh`
- clean up `_ghostty_file` in the early exit path
- improve some `.zshenv` comments
pull/8288/head
Mitchell Hashimoto 2025-08-19 12:07:24 -07:00 committed by GitHub
commit b65b42a5fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 4 deletions

View File

@ -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"
@ -45,6 +46,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.

View File

@ -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").?);
}