You are not logged in.

#1 2013-03-28 16:00:05

skurk
Member
From: Östersund, Sweden
Registered: 2012-03-29
Posts: 8

PS1 from iTerm generates invalid letters in Linux terminals

Hello,

I've been using OSX and iTerm2 for some time and wanted to copy my PS1 to use in Gnome Terminal, XFCE Terminal and LXDE Terminal. However it generates invalid letters.

PS1 Gnome-Terminal

And this is the current PS1.

PS1='\[\e[0;32m\][\e[0;32m\]\u\[\e[m\]\[\e[0;33m\]@\h] \[\e[1;34m\]\W\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]'

The system is a fully updated Arch x64 installation running bash 4.2.45(2)-release.

I can't figure out why this is happening. Does it have to do with $TERM or perhaps the font (Inconsolata-dz)?

Tanks in advance.

Last edited by skurk (2013-03-28 16:11:50)

Offline

#2 2013-03-28 16:13:07

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,553
Website

Re: PS1 from iTerm generates invalid letters in Linux terminals

Take out the \[\e[m\] it serves no purpose but to break it.

And you have *many* redundant codes in there.  Simplify first, then troubleshoot.

Last edited by Trilby (2013-03-28 16:16:37)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2013-03-28 16:21:29

skurk
Member
From: Östersund, Sweden
Registered: 2012-03-29
Posts: 8

Re: PS1 from iTerm generates invalid letters in Linux terminals

Trilby wrote:

Take out the \[\e[m\] it serves no purpose but to break it.

And you have *many* redundant codes in there.  Simplify first, then troubleshoot.

Thanks. Yeah, I will start over. I just find it weird that it is working in OSX and on a friends Raspberry Pi running Arch ARM.

Offline

#4 2013-03-28 16:56:13

skurk
Member
From: Östersund, Sweden
Registered: 2012-03-29
Posts: 8

Re: PS1 from iTerm generates invalid letters in Linux terminals

The only way I managed to solve this great mystery was by using tput which seems a bit stupid. The quad core cpu should have something to do though.

Offline

#5 2013-03-28 16:58:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,553
Website

Re: PS1 from iTerm generates invalid letters in Linux terminals

That will work as is with any non-vte terminal, such as xterm or urxvt.  The problem is still there, and always was, the vte-based terminals just let you know there is a problem while the others ignore it.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2013-03-28 17:12:04

skurk
Member
From: Östersund, Sweden
Registered: 2012-03-29
Posts: 8

Re: PS1 from iTerm generates invalid letters in Linux terminals

Trilby wrote:

That will work as is with any non-vte terminal, such as xterm or urxvt.  The problem is still there, and always was, the vte-based terminals just let you know there is a problem while the others ignore it.

Alright, that answered my initial question. Then I guess OSX Terminal.app and iTerm2 are non vte terminals while Gnome Terminal etc are vte-terminals.

Thanks for your input :-)

Offline

#7 2013-03-28 18:02:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,553
Website

Re: PS1 from iTerm generates invalid letters in Linux terminals

This should have the effect it looks like you intended.  While cleaning it up, I found a few unmatched \[ brackets which were likely the real problem.

PS1='\[\e[0;32m\][\u\[\e[33m\]@\h] \[\e[1;34m\]\W\[\e[32m\]\$ \[\e[1;37m\]'

Are you sure you want that color code at the end, though?  That is a bad way of setting the color of the text you type at the terminal.  You should set this in your terminals default foreground, then the prompt should be the following:

PS1='\[\e[32m\][\u\[\e[33m\]@\h] \[\e[1;34m\]\W\[\e[32m\]\$\[\e[0m\] '

Last edited by Trilby (2013-03-28 18:03:21)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2013-03-28 18:58:09

skurk
Member
From: Östersund, Sweden
Registered: 2012-03-29
Posts: 8

Re: PS1 from iTerm generates invalid letters in Linux terminals

Trilby wrote:

This should have the effect it looks like you intended.  While cleaning it up, I found a few unmatched \[ brackets which were likely the real problem.

PS1='\[\e[0;32m\][\u\[\e[33m\]@\h] \[\e[1;34m\]\W\[\e[32m\]\$ \[\e[1;37m\]'

Are you sure you want that color code at the end, though?  That is a bad way of setting the color of the text you type at the terminal.  You should set this in your terminals default foreground, then the prompt should be the following:

PS1='\[\e[32m\][\u\[\e[33m\]@\h] \[\e[1;34m\]\W\[\e[32m\]\$\[\e[0m\] '

This answer is exactly what I wanted except one missing space (that I fixed). I'm not really experienced doing this, usually just use the default prompt. And according to my OCD the first [ has to be green and the last ] yellow or else I can't get peace of mind.

I salute you sir. I have learned things.

Last edited by skurk (2013-03-28 19:00:06)

Offline

Board footer

Powered by FluxBB