Page 1 of 1

Odd result of terminal history with up arrow (Solved)

Posted: Sun May 14, 2023 11:23 pm
by d-pupp

From the Linux Mint forum

When I use the up arrow in a terminal to scroll through the history, I get some strange results.

If the commands in my history have been short commands, there's no problem. When I get to one that was kind of long, then the next time I hit the up arrow, the first ten or twelve characters of the long command get stuck after the cursor.

Looks like this problem is related to my use of a personalized color prompt

I had this same problem
Old prompt string

Code: Select all

PS1="\[\e]2;\w\a\e[92m\]\W \\[\e[0m\]\e[93m\]\\$ \e[0m\]"

New prompt string Deleted

When I changed from the double quote to single the missing bracket showed up but the problem with my history seems to be the double \\$ as \$ works fine

Edit @Burunduk Thank you your code works mine didn't on longer history commands.
The correct prompt string is Burunduk


Re: Odd result of terminal history with up arrow (Solved)

Posted: Mon May 15, 2023 12:53 am
by bigpup

Which specific terminal?

Exactly where does this code change go?


Re: Odd result of terminal history with up arrow (Solved)

Posted: Mon May 15, 2023 3:35 am
by Burunduk
bigpup wrote: Mon May 15, 2023 12:53 am

Exactly where does this code change go?

Usually into /root/.bashrc. All the explanations are here.

Both examples are problematic. The former has \\[ instead of \[ in the middle and both have an unmatched \] bracket at the end. The latter makes bash to output ~ 0m# as a prompt (in urxvt on Fossapup64) and the length of the prompt is still miscalculated.

To get the colored ~ # prompt:

Code: Select all

PS1="\[\e]2;\w\a\e[92m\]\W \[\e[93m\]\\$ \[\e[0m\]"
# or in single quotes
PS1='\[\e]2;\w\a\e[92m\]\W \[\e[93m\]\$ \[\e[0m\]'

Notes: "\\$" and '\$' are equivalent.
To change the color, there is no need to reset it.

Edit: @d-pupp : With your prompt, the LXTerminal in Vanilla Dpup doesn't output 0m but the length calculation is still wrong. You can see it by typing a command that is wider than the terminal window. By the way, I think the default prompt there is a disaster. It lies like a gas meter (if there is such a saying).


Re: Odd result of terminal history with up arrow (Solved)

Posted: Mon May 15, 2023 1:24 pm
by Marv
Burunduk wrote: Mon May 15, 2023 3:35 am
bigpup wrote: Mon May 15, 2023 12:53 am

Exactly where does this code change go?

Usually into /root/.bashrc. All the explanations are here.

In several of the 'newer pups, F96-CE, another jammypup64, Bookworm Pup64 for example, /etc/profile is included in /root/.bashrc (by . /etc/profile) so the PS1= code is found in /etc/profile or in the case of jammypup64, in /etc/profile.d/ps1.sh, which is included in /etc/profile. Don't shoot me, just the messenger :roll: Great link to the formatting explanation. Thanks


Re: Odd result of terminal history with up arrow (Solved)

Posted: Mon May 15, 2023 3:55 pm
by d-pupp

@bigpup Marv is correct /etc/profile.
You can also use your home directory and put it in .bashrc ie. /root/.bashrc
This will override the one in /etc/profile