wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
16.94k stars 762 forks source link

Unable to use ScrollToPrompt to scroll to the very first prompt on Arch Linux with Bash #5556

Open gitmpr opened 3 months ago

gitmpr commented 3 months ago

What Operating System(s) are you seeing this problem on?

Linux Wayland

Which Wayland compositor or X11 Window manager(s) are you using?

Wayland, GNOME Shell 46.2. This is not very relevant to the issue though, as the problem also happens on Xorg

WezTerm version

20240203.110809.5046fc22-2

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes

Describe the bug

I have configured key bindings in WezTerm to scroll to previous prompts:

{ key = 'UpArrow', mods = 'SHIFT', action = wezterm.action.ScrollToPrompt(-1) },
{ key = 'DownArrow', mods = 'SHIFT', action = wezterm.action.ScrollToPrompt(1) },

The bindings work, but I cannot scroll to the very first prompt.

Troubleshooting steps: After investigating (and also trying with the latest build), I found that the Arch Linux bash package includes /etc/bash.bashrc with this case statement:

case ${TERM} in
  Eterm*|alacritty*|aterm*|foot*|gnome*|konsole*|kterm*|putty*|rxvt*|tmux*|xterm*)
    PROMPT_COMMAND+=('printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"')
    ;;
  screen*)
    PROMPT_COMMAND+=('printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"')
    ;;
esac

This sets PROMPT_COMMAND during Bash startup.

The issue is not with the binary of wezterm, but with the way the PROMPT_STRING gets set up for injecting the OSC133 escape characters for the semantic zones.

According to /etc/profile.d/wezterm.sh, WezTerm assumes that PROMPT_COMMAND is empty:

# Note: This module requires two Bash features which you must not otherwise be
# using: the "DEBUG" trap, and the "PROMPT_COMMAND" variable. If you override
# either of these after bash-preexec has been installed it will most likely break.

To workaround this issue, I commented out the case statement in /etc/bash.bashrc. However, this change may be overwritten by future pacman updates.

Comparison with other distributions: Debian/Ubuntu: /etc/bash.bashrc does not set PROMPT_COMMAND. Fedora: /etc/bashrc sets PROMPT_COMMAND, but I have not tested this yet.

How to address this compatibility issue? Should this be considered a bug in WezTerm or the Arch Linux bash package?

To Reproduce

Configuration

local wezterm = require 'wezterm'
local config = wezterm.config_builder()

config.enable_scroll_bar = true

config.keys = {
  { key = 'UpArrow', mods = 'SHIFT', action = wezterm.action.ScrollToPrompt(-1) },
  { key = 'DownArrow', mods = 'SHIFT', action = wezterm.action.ScrollToPrompt(1) },
}

return config

Expected Behavior

WezTerm should be able to scroll up to previous bash prompts without requiring modifications to bash system files managed by the package manager.

Logs

No response

Anything else?

Could you provide advice on how to address this compatibility issue? Should this be considered a bug in WezTerm or the Arch Linux bash package? I am seeking a solution that will persist through system updates.