3

My Linux Prompt set as:

┌─ (USERNAME@HOSTNAME PATH) ->
└─ $

The PS1 is:

export PS1="\n\[\033[30;1m\]\[\033(0\]l\[\033(B\]\[\033(0\]q\[\033(B\] (\u@\h \[\033[31;1m\]\w\[\033[30;1m\]) ->\n\[\033(0\]m\[\033(B\]\[\033(0\]q\[\033(B\] \`if [ \$? = 0 ]; then echo \[\e[1\;30m\]\\$\[\e[1m\]; else echo \[\e[1\;31m\]\\$\[\e[0m\]; fi\` \[\033[0m\]"

Somehow, it CANNOT be shows correctly from PuTTy, screenshot is: difference

The settings of Window -> Translation in My Putty:

  • Remote character set: -> UTF-8
  • Handing of line drawing characters: -> Use Unicode line drawing code points

How can I show the correct prompt in My PuTTy? (By the way, I tried all options of Handing of line drawing characters:)


PuTTy Prompt still cannot work by using:

if [ -z "$DISPLAY" ]
then
export PS1="\n\[\033[30;1m\]┌─ (\u@\h \[\033[31;1m\]\w\[\033[30;1m\]) ->\n└─ \`if [ \$? = 0 ]; then echo \[\e[1\;30m\]\\$\[\e[1m\]; else echo \[\e[1\;31m\]\\$\[\e[0m\]; fi\` \[\033[0m\]"
else
export PS1="\n\[\033[30;1m\]\[\033(0\]l\[\033(B\]\[\033(0\]q\[\033(B\] (\u@\h \[\033[31;1m\]\w\[\033[30;1m\]) ->\n\[\033(0\]m\[\033(B\]\[\033(0\]q\[\033(B\] \`if [ \$? = 0 ]; then echo \[\e[1\;30m\]\\$\[\e[1m\]; else echo \[\e[1\;31m\]\\$\[\e[0m\]; fi\` \[\033[0m\]"
fi

new_ps1

1
  • Also try KiTTY. The solution presented below works perfectly fine for me.
    – Daniel B
    Apr 28, 2014 at 7:26

1 Answer 1

3

The way to fix this is to stop using "shift out/shift in" sequences, and start including the line-drawing characters directly as UTF-8 (just like you did in your example):

PS1="\n\[\033[30;1m\]┌─ (\u@\h \[\033[31;1m\]\w\[\033[30;1m\]) ->\n└─ \`if [ \$? = 0 ]; then echo \[\e[1\;30m\]\\$\[\e[1m\]; else echo \[\e[1\;31m\]\\$\[\e[0m\]; fi\` \[\033[0m\]"

The problem here is that PuTTY currently does not support the ISO 2022 alternate character set sequences when it's running in UTF-8 mode. There is a PuTTY wishlist entry for this, along with explanation why mixing UTF-8 and ISO 2022 is undesirable.


As in the comments: Note that older versions of Consolas did not have box-drawing characters. You'll have to obtain Consolas from Windows 8.

10
  • WoW, looks cool, I will let you know the result after tried. By te way, I using Gnome-Terminal and PuTTy. How can I know the terminal is PuTTy or Gnome-Terminal? So that I can add the if...else... for PS1
    – Marslo
    Apr 26, 2014 at 11:25
  • By the way, I'm using `sudo fgconsole` -gt 6 to find the Terminal is x-windows or not.
    – Marslo
    Apr 26, 2014 at 11:28
  • @Marslo: Don't bother – just use UTF-8 in both cases. GNOME Terminal has supported UTF-8 for many years... Apr 26, 2014 at 11:46
  • 1
    @Marslo: Generally, such checks should be more specific. That is, think for a moment why you're checking for it. // Does the setting depend on X11? Then check if $DISPLAY is set; do not use fgconsole, it'll fail on systems where you don't have root, it'll fail when your display manager decides to start Xorg on vt1 or vt2, or when VTs disappear from Linux, or when you're in a rescue shell on tty9... // Does it depend on a function that PuTTY has but GNOME Terminal hasn't? Try again; the same UTF-8 actually works fine in both, so skipping the check would make things simpler. Apr 26, 2014 at 11:52
  • 1
    Ah, interesting. It's probably just missing in your font, then? Older versions of Consolas did not have it. Apr 28, 2014 at 7:18

You must log in to answer this question.

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