Skip to content

fix(themes/powerline): ensure prompt starts on a new line#2385

Open
seefood wants to merge 2 commits intoBash-it:masterfrom
seefood:fix/2372-powerline-missing-newline
Open

fix(themes/powerline): ensure prompt starts on a new line#2385
seefood wants to merge 2 commits intoBash-it:masterfrom
seefood:fix/2372-powerline-missing-newline

Conversation

@seefood
Copy link
Copy Markdown
Contributor

@seefood seefood commented Apr 18, 2026

Summary

When a command produces output without a trailing newline (e.g. echo -n foo), the existing \e[G (move to column 1) in PS1 overwrites that output with the prompt. This adds a missing-newline handler at the top of __powerline_prompt_command:

printf '%b' '\e[7m%\e[0m\r\e[K'

How it works:

  • \e[7m%\e[0m — prints a reversed-video % at the current cursor position. If the previous command left the cursor mid-line, this character is briefly visible as a "missing newline" indicator (same convention as zsh's PROMPT_SP)
  • \r — carriage return to column 1 of the current line
  • \e[K — clear from column 1 to end of line

Result:

  • Previous command ended with newline: cursor was already at column 1 on a blank line → % is printed and immediately cleared → no visible change
  • Previous command had no trailing newline: % appears at the end of the partial output, then \r\e[K clears the entire line → prompt renders cleanly on what is now an empty line

The existing \e[G in PS1 is kept as-is (it becomes a harmless no-op since we are already at column 1 after the printf).

Note: powerline-multiline uses \e[B (cursor down) instead of \e[G and has different behaviour; that theme is out of scope for this fix.

Test plan

  • echo -n foo — verify % appears briefly then prompt renders on a clean new line, foo is not overwritten
  • Normal commands (echo foo, ls) — verify no extra blank line is inserted
  • Works in powerline, powerline-plain, and powerline-naked (plain and naked inherit __powerline_prompt_command from base)

Fixes #2372

🤖 Generated with Claude Code

seefood and others added 2 commits April 18, 2026 18:42
When a command's output has no trailing newline, \e[G (column 1) in PS1
would overwrite that output with the prompt. Add a missing-newline
indicator in PROMPT_COMMAND: reversed-video % marks the incomplete line,
then \r\e[K moves to column 1 and clears it, so the prompt always
renders cleanly regardless of the previous command's output.

Fixes Bash-it#2372

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verifies that __powerline_prompt_command:
- outputs the \e[7m%\e[0m\r\e[K sequence to stdout
- outputs it as the very first bytes (before segment/PS1 content)

Uses a no-op stub segment and a _save-and-reload-history stub to avoid
pulling in every plugin that the default segments depend on.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Powerline overwrites output of last command when it doesn't end with newline

1 participant