Skip to content

Bash Prompt improperly line-wrapping #1

@JangoSteve

Description

@JangoSteve

Hey, I was having two problems with my bash prompt:

  • When cycling through the history, if one of the commands was greater than or equal to 35 characters long, the prompt will then keep the first 8 characters in the prompt and they won't go away until the next line is triggered with ENTER.
  • When a really long command is typed that reaches the end of the terminal (i.e. number of characters typed is greater than COLUMNS), it starts the command back on the first line, overwriting from the beginning of the prompt so you can't see what was already typed, instead of continuing on to the second line. Has something to do with parse_last_status function.

I narrowed the issue down to the function that colors my prompt based on the exit status of the last command. In an effort to finally figure these out, started googling for how other people were doing this and I came across yours.

I noticed that your prompt suffers the same issues, so now that I've figured it out, I just thought I'd let you know in case you've been gradually and silently suffering as I had been.

It's because the prompt is including the color coding characters from this function in the total length of the command prompt even though they're not displayed, so it's messing up when the prompt needs to wrap to the next line. See this article.

Here was my solution. Basically, just surrounded that function output with \[\]. You're might be a bit more involved since your function includes actual "exited " text when it's non-zero.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions