In my terminal, when I'm typing over the end of a line, rather than start a new line, my new characters overwrite the beginning of the same line.

I have seen many StackOverflow questions on this topic, but none of them have helped me. Most have something to do with improperly bracketed colors, but as far as I can tell, my PS1 looks fine.

Here it is below, generated using bash -x:

PS1='\[\033[01;32m\]\w \[\033[1;36m\]☔︎ \[\033[00m\] '

Yes, that is in fact an umbrella with rain; I have my Bash prompt update with the weather using a script I wrote.

EDIT: My BashWeather script actually can put any one of a few weather characters, so it would be great if we could solve for all of these, or come up with some other solution:

☂☃☽☀︎☔︎

If the umbrella with rain is particularly problematic, I can change that to the regular umbrella without issue.

share|improve this question
    
This is probably an issue with your locale, with bash being confused about how long your prompt is: the umbrella takes the space of one character, but is represented by a 5-byte sequence in UTF-8. – chepner Apr 7 '14 at 20:40
    
Hm. If this is the case, how might I go about fixing this? I know how to deal with it in Python, but not in Bash. – jdotjdot Apr 7 '14 at 20:45
    
    
I think it is an issue with bash and Unicode characters whose UTF-8 encodings are longer than 4 bytes. See my answer below. – chepner Apr 7 '14 at 21:17
    
@jdotjdot: Try setting WEATHERCHAR to just the umbrella with rain character ($'\u2614'). If it looks ok, then you can do the same with the other symbols. – rici Apr 9 '14 at 3:45
up vote 1 down vote accepted

This almost works for me, so should probably not be considered a complete solution. This is a stripped down prompt that consists of only an umbrella and a space:

PS1='\342\230\[\224\357\270\] '

I use the octal escapes for the UTF-8 encoding of the umbrella character, putting the last three bytes inside \[...\] so that bash doesn't think they take up space on the screen. I initially put the last four bytes in, but at least in my terminal, there is a display error where the umbrella is followed by an extra character (the question-mark-in-a-diamond glyph for missing characters), so the umbrella really does occupy two spaces.

This could be an issue with bash and 5-byte UTF-8 sequences; using a character with a 4-byte UTF-encoding poses no problem:

# U+10400 DESERET CAPITAL LETTER LONG I
# (looks like a lowercase delta)
PS1='\360\220\220\200 '
share|improve this answer
    
there is no such thing as a 5-byte UTF-8 sequence. The graph being inserted into the prompt script consists of two unicode codepoints, each of is encoded into a three-byte UTF-8 sequence. The non-printing brackets need to go around the second codepoint. (See my answer, which I think may still be a bit confusing. But then, it's unicode.) – rici Apr 8 '14 at 19:34
    
Ah, very nice. I noticed in the Mac OS X character viewer that there were two Unicode code points listed, which thoroughly confused me, so I just parroted the 5-byte sequence it gave for the UTF-8 encoding. – chepner Apr 8 '14 at 19:57
    
Providing simply the UTF-8 encoding in octal seemed to be the way to go to fix it for all of them. Sun ended up having that problem as well--but as far as I can tell, looks like it's working now. – jdotjdot Jun 12 '14 at 0:03

The symbol being printed ☔︎ consists of two Unicode codepoints: U+2614 (UMBRELLA WITH RAIN DROPS) and U+FE0E (VARIATION SELECTOR-15). The second of these is a zero-length qualifier, which is intended to enforce "text style", as opposed to "emoji style", on the preceding symbol. If you're viewing this with a font can distinguish the two styles, the following might be the emoji version: ☔︉ Otherwise, you can see a table of text and emoji variants in Working Group document N4182 (the umbrella is near the top of page 3).

In theory, U+FE0E should be recognized as a zero-length codepoint, like any other combining character. However, it will not hurt to surround the variant selector in PS1 with the "non-printing" escape sequence \[…\].

It's a bit awkward to paste an isolated variant selector directly into a file, so I'd recommend using bash's unicode-escape feature:

WEATHERCHAR=$'\u2614\[\ufe0e\]'
#...
PS1=...${WEATHERCHAR}...

Note that \[ and \] are interpreted before parameter expansion, so WEATHERCHAR as defined above cannot be dynamically inserted into the prompt. An alternative would be to make the dynamically-inserted character just the $'\u2614' umbrella (or whatever), and insert the $'\[\ufe0e\]' in the prompt template along with the terminal color codes, etc.

Of course, it is entirely possible that the variant indicator isn't needed at all. It certainly makes no useful difference on my Ubuntu system, where the terminal font I use (Deja Vu Sans Mono) renders both variants with a box around the umbrella, which is simply distracting, while the fonts used in my browser seem to render the umbrella identically with and without variants. But YMMV.

share|improve this answer
    
Given your explanation in a comment to my answer, is the variation selector even necessary? That is, is there significant difference in the prompt between using U+2614 and U+2614 U+FE0E? – chepner Apr 8 '14 at 20:13
    
@chepner: I don't know, since I don't have a Mac handy. According to Wikipedia, you can tell the difference on a Mac, and OP apparently uses one, so is probably in a better position to tell than I am. – rici Apr 8 '14 at 20:36
    
I'll look into this and get back to you both. I am on a Mac (though moving back to Linux soon...) – jdotjdot Apr 9 '14 at 5:32
    
For the time being I'm testing by eliminating the umbrella+rain character entirely and replacing with only umbrella, since those appear to be only single unicode codepoints. I am testing and will see if I encounter the same problem. – jdotjdot May 24 '14 at 5:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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