0

I'm using Windows 10 with WSL2. In all the terminals I have tried so far, I quickly encounter a broken command line. After pressing ENTER, the actual command appears differently, parts of the command prompt are deleted, editing does not occur at the cursor position, and random spaces are added, among other issues. Today has been particularly challenging, making it difficult for me to work effectively.

Maybe it happens after scrolling the history with the up/down arrow keys.
Restarting WSL, clearing terminal, restarting terminal don't help.
So after restarting I scroll the history and boom!

Any idea how to fix it? I read there's some RESET command for terminal. How to reset? Maybe that could help...

Here just one example: after executing git log... I return back to the command with the arrow up key but the end of the command prompt is partially destroyed as well as the beginning of the command. enter image description here

[16:25:20] blade@DESKTOP-VQABTK7:/bytex/site$ echo $PS1; echo;
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

2
  • To successfully wrap lines and edit the command line, the shell needs to be told which characters in your prompt string cause the cursor position to advance (= regular characters) and which won't (= escape sequences to set colors, update the terminal title etc.). Your symptoms would be exactly what happens if this has not been done correctly. Which shell are you using, and what is the value of your prompt string ($PS1 in POSIX-compatible shells)?
    – telcoM
    Commented Jun 6, 2023 at 14:02
  • @telcoM added to the question Commented Jun 6, 2023 at 14:27

1 Answer 1

2

This looks like a fairly standard colorized version of a Debian/Ubuntu/Mint default prompt.

\[           # begin non-advancing characters
\e]0;        # escape sequence to update terminal title
\u@\h: \w    # sets title to <user>@<host>: <working directory>
\a           # end terminal title
\]           # end non-advancing characters
${debian_chroot:+($debian_chroot)} # if within a Debian chroot, name of the chroot env
\[           # begin non-advancing characters
\033[01;32m  # escape sequence to set colors
\]           # end non-advancing characters
\u@\h        # output <user>@<host> for the prompt
\[           # begin non-advancing characters
\033[00m     # escape sequence to set colors
\]           # end non-advancing characters
:            # output :
\[           # begin non-advancing characters
\033[01;34m  # escape sequence to set colors
\]           # end non-advancing characters
\w           # output current working directory
\[           # begin non-advancing characters
\033[00m     # escape sequence to set colors
\]           # end non-advancing characters
\$           # output $ if a regular user, or # if root
<space>      # output a space after prompt

Note that the terminal title is also correctly counted as non-advancing characters.

But this would result in a prompt that looks like (simulated without colors):

blade@DESKTOP-VQABTK7:/bytex/site$ 

Where does the timestamp at the beginning come from?

Do you have $PROMPT_COMMAND set?

To produce your prompt cleanly, remove whatever hack currently causes the timestamp prefix to your prompt, and try this PS1 setting instead:

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

You must log in to answer this question.

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