Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy/paste doesn't work properly when changing prompt colors #134

Closed
olivierpons opened this issue Oct 29, 2018 · 7 comments
Closed

Copy/paste doesn't work properly when changing prompt colors #134

olivierpons opened this issue Oct 29, 2018 · 7 comments

Comments

@olivierpons
Copy link

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...

@willpower232
Copy link

Your PS1 seems to also produce similar results in real bash (tried in Ubuntu) so it sounds like your specific prompt does funny things to bash(?)

@olivierpons
Copy link
Author

olivierpons commented Oct 29, 2018

It should just change the colors of the prompt (and that's what it does actually). Do you think it does something else we dont see? I've asked here (hoping to get an answer).

@mintty
Copy link
Owner

mintty commented Oct 29, 2018

Your prompt is broken. You need to enclose escape sequences in pairs of \[ and \] or you'll have that offset problem. Not a mintty issue, as Will observed.

@mintty
Copy link
Owner

mintty commented Oct 29, 2018

Sorry, should have been \[ and \]. Fixing above. Read the bash manual.

@olivierpons
Copy link
Author

I'm sorry you're right, I should take some time to read the bash manual. Sorry for that.

@willpower232
Copy link

I had no idea this was a thing. FWIW my PS1 ends in a newline which I presume resolves everything...

@mintty
Copy link
Owner

mintty commented Oct 30, 2018

Admittedly, the bash manual is not very clear about the importance of using the escape embedding of non-printing characters in order to enable bash (or rather readline) to maintain its proper column position.
In tcsh, it's %{ and %}.

@mintty mintty mentioned this issue Jan 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants