From e34b37342620c32ab1420105236c343853742d98 Mon Sep 17 00:00:00 2001 From: Marius Svechla Date: Wed, 3 Apr 2024 21:27:53 +0200 Subject: [PATCH] shell-integration: implement no-title option This adds a new option to the shell integration feature set, `no-title`. If this option is set, the shell integration will not automatically update the window title. --- src/config/Config.zig | 5 ++++- src/shell-integration/bash/ghostty.bash | 8 +++++--- src/shell-integration/zsh/ghostty-integration | 12 +++++++----- src/termio/shell_integration.zig | 1 + 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 1bf9474f5..6ca64ca01 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -839,7 +839,9 @@ keybind: Keybinds = .{}, /// /// * `sudo` - Set sudo wrapper to preserve terminfo. /// -/// Example: `cursor`, `no-cursor`, `sudo`, `no-sudo` +/// * `title` - Set the window title via shell integration. +/// +/// Example: `cursor`, `no-cursor`, `sudo`, `no-sudo`, `title`, `no-title` @"shell-integration-features": ShellIntegrationFeatures = .{}, /// Sets the reporting format for OSC sequences that request color information. @@ -3378,6 +3380,7 @@ pub const ShellIntegration = enum { pub const ShellIntegrationFeatures = packed struct { cursor: bool = true, sudo: bool = false, + title: bool = true, }; /// OSC 4, 10, 11, and 12 default color reporting format. diff --git a/src/shell-integration/bash/ghostty.bash b/src/shell-integration/bash/ghostty.bash index 163ce120b..251faf11e 100644 --- a/src/shell-integration/bash/ghostty.bash +++ b/src/shell-integration/bash/ghostty.bash @@ -70,9 +70,11 @@ function __ghostty_precmd() { } fi - # Command - PS0=$PS0'$(__ghostty_get_current_command)' - PS1=$PS1'\[\e]2;$PWD\a\]' + if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_TITLE" != 1 ]]; then + # Command + PS0=$PS0'$(__ghostty_get_current_command)' + PS1=$PS1'\[\e]2;$PWD\a\]' + fi fi if test "$_ghostty_executing" != "0"; then diff --git a/src/shell-integration/zsh/ghostty-integration b/src/shell-integration/zsh/ghostty-integration index 438285a5c..28159f41c 100755 --- a/src/shell-integration/zsh/ghostty-integration +++ b/src/shell-integration/zsh/ghostty-integration @@ -194,11 +194,13 @@ _ghostty_deferred_init() { _ghostty_report_pwd" _ghostty_report_pwd - # Enable terminal title changes. - functions[_ghostty_precmd]+=" - builtin print -rnu $_ghostty_fd \$'\\e]2;'\"\${(%):-%(4~|…/%3~|%~)}\"\$'\\a'" - functions[_ghostty_preexec]+=" - builtin print -rnu $_ghostty_fd \$'\\e]2;'\"\${(V)1}\"\$'\\a'" + if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_TITLE" != 1 ]]; then + # Enable terminal title changes. + functions[_ghostty_precmd]+=" + builtin print -rnu $_ghostty_fd \$'\\e]2;'\"\${(%):-%(4~|…/%3~|%~)}\"\$'\\a'" + functions[_ghostty_preexec]+=" + builtin print -rnu $_ghostty_fd \$'\\e]2;'\"\${(V)1}\"\$'\\a'" + fi if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_CURSOR" != 1 ]]; then # Enable cursor shape changes depending on the current keymap. diff --git a/src/termio/shell_integration.zig b/src/termio/shell_integration.zig index f8266f969..95d86eaae 100644 --- a/src/termio/shell_integration.zig +++ b/src/termio/shell_integration.zig @@ -50,6 +50,7 @@ pub fn setup( // Setup our feature env vars if (!features.cursor) try env.put("GHOSTTY_SHELL_INTEGRATION_NO_CURSOR", "1"); if (!features.sudo) try env.put("GHOSTTY_SHELL_INTEGRATION_NO_SUDO", "1"); + if (!features.title) try env.put("GHOSTTY_SHELL_INTEGRATION_NO_TITLE", "1"); return shell; }