Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add ability to toggle zsh-integration title change #4479

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/shell-integration/zsh/ghostty-integration
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,30 @@ _ghostty_deferred_init() {

if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_TITLE" != 1 ]]; then
# Enable terminal title changes.

# Heredoc assignment to variable without cat from https://stackoverflow.com/a/1655389

read -r -d '' _ghostty_precmd_title_epilogue <<'END'
Copy link
Contributor

@anund anund Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only reason the original code, ~3 years back in kitty, chose to add the title code here via an append was stylistic. Rather than bending over backward with read please add the ifs to their original functions. Switching on the original envvar would be better too.

if [[ "$GHOSTTY_SHELL_INTEGRATION_TOGGLE_TITLE_OFF" != 1 ]]; then
builtin print -rnu $_ghostty_fd $'\e]2;'"${(%):-%(4~|…/%3~|%~)}"$'\a'
fi
END

read -r -d '' _ghostty_preexec_title_epilogue <<'END'
if [[ "$GHOSTTY_SHELL_INTEGRATION_TOGGLE_TITLE_OFF" != 1 ]]; then
builtin print -rnu $_ghostty_fd $'\e]2;'"${(V)1}"$'\a'
fi
END

functions[_ghostty_precmd]+="
builtin print -rnu $_ghostty_fd \$'\\e]2;'\"\${(%):-%(4~|…/%3~|%~)}\"\$'\\a'"
${_ghostty_precmd_title_epilogue}"

functions[_ghostty_preexec]+="
builtin print -rnu $_ghostty_fd \$'\\e]2;'\"\${(V)1}\"\$'\\a'"
${_ghostty_preexec_title_epilogue}"

unset _ghostty_precmd_title_epilogue
unset _ghostty_preexec_title_epilogue

fi

if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_CURSOR" != 1 ]]; then
Expand Down