4

Here it is:

Captures git branch for prompt:

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\W\[\033[0;31m\]\$(parse_git_branch)⚡️\[\033[0;39m\] "

It is not wrapping lines in my terminal correctly (it runs over the current line when it is supposed to wrap to the next line) and it also inserts a random alpha character (that cannot be deleted) at the beginning of my prompt (yet, this has no effect of commands I am trying to execute).

Mingye Wang
  • 1,181
  • You should use single quotes instead of double quotes in PS1='...'. – Mikel Oct 27 '15 at 17:52
  • @Mikel That doesn't matter. – Mingye Wang Oct 27 '15 at 17:54
  • 1
    I cannot reproduce the problem. Check your terminal emulator encoding, for that ⚡️ character. And why do you export your PS1? – Mingye Wang Oct 27 '15 at 18:01
  • 1
    @Arthur2e5 It requires less escaping, e.g. for \$(parse_git_branch) you can just write $(parse_git_branch). But you're right that the \[ and \] are getting escaped correctly even inside double quotes, which is the part I was worried about. – Mikel Oct 27 '15 at 18:26
  • Well, this is interesting... after I simply deleted my emoji - it starts working again... so that means my terminal doesn't like the encoding all of a sudden then??? – one_mile_up Oct 27 '15 at 18:54
  • For your reference, on my computer 26A1 FE0F displays like a 1-en glyph. I think you should use the 'text' variant, or use a monospace font that knows to override emojis. http://www.fileformat.info/info/unicode/char/26a1/index.htm – Mingye Wang Oct 27 '15 at 19:38

3 Answers3

2

If you're like me and you MUST have the emoji in your prompt, this fixed the line wrap problem for me:

PS1="\[⚡️\]"

Essentially, this makes the lightning bolt not be counted in the prompts length, better explained in this askubuntu thread.

epylinkn
  • 121
1

Had the same issue, not wrapping lines. However, the green leaf emoji appears in my vim like this:

�~_~M~C

Instead of using [ ] to escape the whole sequence, I left the first one out:

�\[~_~M~C \]

Now, wrapping works and column count is also correct.

Lei Xu
  • 11
0

@Arthur2e5 -- you pretty much figured it out! It was that lightning bolt emoji! For some odd reason, I can use other emoji's, but NOT the lightning bolt... weird - I know. Thank you for helping me diagnose the problem though... it's been bugging me for about a month now! LoL!