0

Open a prompt, try to do this:

  • type this code: export PS1="\e[1;30m-30-\e[m >"
  • copy it with your mouse (select the code + copy it (I have auto-copy when I select with the mouse enabled))
  • close the prompt
  • open a brand new prompt
  • immediately paste it (SHIFT INS)
  • type "HOME" key and "END" key, you'll see the cursor go to logical positions (start and end of the code)
  • now press ENTER
  • you prompt changes the colors
  • immediately paste it (SHIFT INS)
  • type "HOME" key and "END" key, you'll see the cursor go to illogical positions (offset problem)

This means if I apply colors to the prompt I can't copy/paste + change my copied code...

NB: I'm asking it here because I thought it was a problem of wsltty here but it seems it's only related to what I'm trying to assign: export PS1="\e[1;30m-30-\e[m >"... and I dont see a problem. It should just change the colors of the prompt (and that's what it does actually). But it seems it does something more I dont see. Does somebody know what it could be?

3

You need to enclose escape sequences in pairs of \[ and \] or you'll have that offset problem.

| improve this answer | |
  • May I ask you to add in your answer the working version of export PS1="\e[1;30m-30-\e[m >" so I can make the link? Thank you very much – Olivier Pons Oct 29 '18 at 13:02
0

user1274247 is right, you need to enclose escape sequences.

Here's what my PS1 looks like.

\[\033]0;\u@\h:\w\007\]\[\033[01;31m\]\h\[\033[01;34m\] \w \$\[\033[00m\]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.