Tuesday, December 5, 2023
rated 0 times [  0] [ 0]  / answers: 1 / hits: 761  / 2 Years ago, thu, march 3, 2022, 6:09:25

This question is a follow up on the answer to this question, regarding changing the color of the user input prompt in the XFCE terminal: Ubuntu terminal (Xfce): making input commands different font color from output text

Since I am not allowed to comment there (min 50 reputation), I had to open a new question.

Following the answer, I used the following command:

PS1='e[1;36mu@h W]$e[0m '

This keeps the format the same as default, but changes the color to cyan, as expected.

However, I am getting some very strange behavior. Sometimes the cursor will jump back on the input line, and sometimes it will show old text that should not be there. Sometimes it splits into two lines such that I continue typing on the line above. For example:

Say that I want to do:

$ cd /some/path/to/a/directory

but as I type it it becomes like this:

$ cd /some/pa/directoryath/to

if I type enter, it will still read the command correctly, it is just the display that is wrong. When it happens, if I try to use the backspace it will turn into something like this:

$ cd /some/pa/directoryath/to
$ cd /some/pa/directo
$ cd /some/pa -------- at this point I cannot erase anything else,
in the display some of the characters are still
lingering, but if I type enter there is nothing on the input line

Another example, say that I have the following displayed:

$ ls
folder1 folder2 folder3 folder4

and now I want to type some other command, then the following might happen:

$ ls
folder1 folder2 folder3 folrectory
$ cd /some/path/to/a/di

Once again, if I type enter the input is recognized correctly, but the display is screwed up.

The issue occurs most frequently, but not exclusively, when I type the up arrow to get a previous command, or when the input line approaches the right edge of the window.

More From » xfce4-terminal


I tested and notice a problem with your prompt too, it seems to expect the right margin too early and makes a line break.

Please try this one, that I use

if [ "$USER" = root ]; then
PS1='[033[01;31m]$(statstring)[033[00m]${debian_chroot:+($debian_chroot)}[033[01;31m]u@h[033[00m] [033[01;34m]w[033[00m] $ '
PS1='[033[01;31m]$(statstring)[033[00m]${debian_chroot:+($debian_chroot)}[033[01;32m]u@h[033[00m] [033[01;34m]w[033[00m] $ '

and if it works, you can put it into your ~/.bashrc at least for interactive shells. I use

case "$TERM" in

to decide when to use it, and you may check for something that matches your setup.

Edit: Add a function to create statstring before you set the prompt in ~/.bashrc

function statstring {
if [ "0" != $RC ]; then
printf "[$RC] "

[#1174] Friday, March 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 380
Total Questions: 109
Total Answers: 101

Location: England
Member since Tue, Sep 8, 2020
3 Years ago