0

I use bash and have been using Latin1 encoding my whole life, since I've always had problems when trying to migrate to the advised UTF-8. I finally gave up, and I am migrating everything to UTF-8. What a pain...

I have a specific problem when doing SSH with all rxvt, urxvt and xterm. My remote prompt is set as:

 PS1="\033[32m\[\h:\W> \]\033[0m"

This shows a nice green thing like

 MyBox:~> 

After migrating to utf-8 (all lang and locales from en_US to en_US.UTF-8), my UP, DOWN arrows (back/forward history), DEL and BS don't get track of the position in the line (destroying the prompt, deleting the wrong letters, etc). A mess. Example:

Orion:~> ssh me@MyBox.mydomain...
Last login: Sat Oct  3 13:47:42 2020 from NNN.NNN.NNN.NNN
MyBox:~> ls
amp/  ap/  bin/  phantomjs/  varios/
MyBox:~> 

After hitting UP several times to go backwards in history, it reads:

MyBox:~vi .basrc

instead of

MyBox:~> vi .basrc

so some characters vanished. This makes a mess to edit a command line, for example.

I tried fiddling with the ~/.inputrc file in the remote SSH machine without luck. It seems the shortcuts are correct.

Any ideas?

1 Answers1

1

You are mis-setting the prompt. The \[ ... \] segment should enclose the non-printing characters, but in yours it encloses only the printing characters. (This is nothing to do with Latin1 vs UTF-8, you'll be reassured to know.)

Try this instead

PS1="\[\033[32m\]\h:\W> \[\033[0m\]"

See the PROMPTING section in the shell manual (man bash in my case) for the details.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287