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

Bash shell_integration breaks multiline dynamic prompts on resize #7229

Closed
Nan0Scho1ar opened this issue Mar 15, 2024 · 1 comment
Closed
Labels

Comments

@Nan0Scho1ar
Copy link

Nan0Scho1ar commented Mar 15, 2024

In bash, I call a function to set a dynamic prompt like this: export PS1='$(some_func)' (Must be single quotes or it will eval the command substitution before setting the envar and thus will not be dynamic). This method works fine in every terminal emulator I've tried (including kitty with shell_integration disabled).

This also mostly works fine in kitty when shell_integration is enabled, unless the function call is used to set a multiline prompt. In this case, resizing the window causes part of the prompt to disappear.

Here is a minimal way to reproduce this which demonstrate the difference in behaviour between shell_integration enabled/disabled:

Working as expected

Start both kitty and bash without any config, aside from explicitly disabling kitty shell integration:

PS1="> " PROMPT_COMMAND= kitty -c NONE -o shell_integration=disabled -o shell='bash --login --noprofile --norc'

Then in that terminal create a function which returns a simple multiline prompt, and set the PS1 to call it:

my_func() { echo -e "┌─[$(pwd)]\n└──╼ "; }; export PS1='$(my_func)';

This shell now has a dynamic multiline prompt (which you can see by changing directories).
Because shell_integration is disabled. Resizing the window does not cause any issues.


Prompt disappears

Again, start both kitty and bash without any config. But this time we are explicitly enabling kitty shell integration:

PS1="> " PROMPT_COMMAND= kitty -c NONE -o shell_integration=enabled -o shell='bash --login --noprofile --norc'

Then, exactly as before, in that terminal create a function which returns a simple multiline prompt, and set the PS1 to call it:

my_func() { echo -e "┌─[$(pwd)]\n└──╼ "; }; export PS1='$(my_func)';

Again we now have a dynamic multiline prompt. But this time if we even slightly resize the window, the first line of the prompt disappears.

Before Resize:
image

After Resize:
image

Resulting PS1:
image


System Info

Software Version
OS Fedora 38
Linux Kernel 6.6.14-100.fc38.x86_64
Bash version 5.2.26(1)-release (x86_64-redhat-linux-gnu)
kitty 0.29.2
kitty-shell-integration 0.29.2
@kovidgoyal
Copy link
Owner

You want

export PS1="$(my_func)"

Note the double quotes.

The reason is that bash does not redraw the first line of a multiline
prompt on resize. And kitty will delete it with shell integration. See
lines 163 onwards in kitty.bash for details.

Of course using double quotes means pwd is not updated, so what you
actually need is something like

export PS1='┌─[$(pwd)\n└──╼ ';

basically the newline needs ot be a static part of PS1 not a dynamically
output one.

Or just use a better shell like zsh/fish that doesnt have this
limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants