1

The question closely follows this one, except that I did what the git-prompt.sh does myself.

However, I started noticing weird rendering issues, where long lines do not wrap on the next console line, but rather override the starting of the same line, much like as \r was appended to the $PS1 sequence which brings the cursor at beginning of the line. Moreover, if I undo the command with up arrow, then current line (the one we were about to write the too-long command, overridden) gets completely removed.

Attached a screenshot of what I am referring to.

However, there's no trace of such CR character anywhere in the PS1 string. I tested with the git-prompt.sh, and see the same result. It is definitely something messing with the PS1 string, since if I do not set it and let the default [\u@\h \W]\$, then the issue disappears.

The modified PS1 string is:

\[\e]0;[\u@\h] \w\a\][\[\[\033[01;31m\]\]\u@\h\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\] (\[\033[01;33m\]main\[\033[00m\])]\$

Any ideas?

enter image description here

10
  • 1
    Please edit the question to present the exact assignment you are using to set PS1, not just the value you think is being assigned. Commented Nov 5 at 15:46
  • What is the value of your TERM variable? Commented Nov 5 at 15:51
  • @JohnBollinger it is as simple as PS1="${_ps1_str}$(__git_branch)]\$ " where the first variable is the string you see + the branch part if it exists. I do save the original one before modifying it. Commented Nov 5 at 15:52
  • 1
    It seems like you figured out the problem. If so, then congratulations, and please consider either writing a self-answer or deleting the question. Commented Nov 5 at 16:14
  • 1
    typeset -p PS1 should generate an assignment statement that leaves no doubt as to what's in the variable; it also gives us something we can cut-n-paste into our environments without the need to have an environment that looks exactly like yours, eg, no need to reproduce _ps1_str and __git_branch Commented Nov 5 at 21:24

1 Answer 1

1

As suggested, I found the issue and so posting it in an answer.
I did not realize that in the first coloring sequence, the opening/closing escape sequence \[ and \] were duplicated, creating a nesting which was likely the cause.
Specifically, this:

\[\[\033[01;31m\]\]

before \u@\h.

EDIT:

The fix is simply removing the outer escape sequence, i.e.:

\[\033[01;31m\]

The issue at the origin was that in generating the string, I had forgotten manually inserted \[\] (outer ones), before I wrote a simple function that returns a code color, already wrapped with escape sequence. By calling the function, and not removing the previously manually added one, I fell into the trap.

Sign up to request clarification or add additional context in comments.

2 Comments

Show how you fixed it.
Well done! Then try: PS1='\[\e]0;[\u@\h] \w\a\][\[\033[01;31m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\]${testvar+ (\[\033[01;33m\]$testvar\[\033[00m\])}]\$ ' followed by testvar="Hello world!" and unset testvar ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.