0

Hi I am using Fedora 37 and came across next problem.
Adding export PS1="\e[43;39m[\t]\w\r\n[\u@\h]\\$\e[40m \[$(tput sgr0)\]" to my .bashrc file in /home/username in my case led up to this unexpected behaviour. As I start typing bash commands and fill the whole line the characters don't go to the next line but just continue to get outprinted in the same line overriding the content at the begging of the line. As example: 1 I'm not really familiar with bash syntax so I would appreciate help from a fellow expert.

5
  • 2
    color codes like \e[43;39m also need to be enclosed in \[ ... \].
    – su.root
    Commented Dec 3, 2022 at 12:40
  • Thanks, so a correct way would be to do it like this? \e[43;39m\]
    – GabrijelOkorn
    Commented Dec 3, 2022 at 12:59
  • 1
    No, \[\e43;39m\] Commented Dec 3, 2022 at 13:34
  • That way the colors don't even work.
    – GabrijelOkorn
    Commented Dec 3, 2022 at 13:41
  • "does not work" cannot help others help you. please take a look at stackoverflow.com/help/how-to-ask
    – su.root
    Commented Dec 3, 2022 at 13:55

1 Answer 1

1

As pynexj indicated, you need braces. However, the tput is probably nullifying more than you expect. You should keep it simple with the basic escape sequence.

Also you have "[40m" in your original string. I believe that was a mistype and should be "[0m", which is the sequence for "reset attributes".

Try using this instead:

export PS1="\[\e[43;39m\][\t]\w\r\n[\u@\h]\\$\[\e[0m\]"

Also, I would personally use ";30m" instead of ";39m". The corresponding definition would be:

export PS1="\[\e[43;30m\][\t]\w\r\n[\u@\h]\\$\[\e[0m\]"

For comparison, on Ubuntu MATE 20.04, the .bashrc definition is:

export PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "

Since I experienced the same problem using your original string, I can explain what happened.

As you let the input buffer fill, it wrapped-around early, before reaching the terminal width, and this for the distance equivalent to the count of characters that were not properly "framed" by the square brackets. Not being framed properly, while not visible, they were counted as part of the linewidth for line buffer character count, so it did a "carriage return" to column one, overwriting what was there. Because of that, the curses logic didn't encounter the "line end" condition, so it did not kick in for the expected linefeed.

1
  • Thank you, I tried your solution and it works. Thank you also for the explanation, it was helpful.
    – GabrijelOkorn
    Commented Dec 6, 2022 at 22:09

Not the answer you're looking for? Browse other questions tagged .