Re: Little pb with fancy prompt

From: Icarus Sparry (usenet_at_icarus.freeuk.com)
Date: 05/29/04


Date: Sat, 29 May 2004 20:02:20 GMT

On Sat, 29 May 2004 18:27:10 +0200, Frédéric Mayot wrote:

> I modified my bash prompt:
>
> PS1='\e[31;40m\u@\h:\e[32;40m\w\e[31;40m\$\e[0m '
>
> but it happens something strange: after 50 characters typed, it returns
> to the beginning of the line erasing what has been already typed.

The reason for this is that bash is counting the characters being output,
and assuming that each of them takes a space on the screen. However this
looks as if you are using ANSI escape sequences (or something based on
them), so that the \e[31;40m will actually take no space at all. To tell
bash that these take no space, put them inside a \[ \] pair, e.g.

PS1='\[\e[31;40m\]\u@\h:\[\e[32;40m\]\w\[\e[31;40m\]\$\[\e[0m\] '

This is described in the info page and the man page.



Relevant Pages

  • Re: root /etc/csh
    ... but I can give you a damn good reason why it shouldn't be: ... A statically-linked version of bash would waste significant amounts ... Wouldn't a single in-memory instance of the bash text ... should be rebuilt any time there is a security update to a shared ...
    (freebsd-questions)
  • Re: Connections to Akamai?
    ... > Recommend deinstall product and convert to Linux! ... I will bash MS with the best of the *nix folks, but...the reason I am ...
    (microsoft.public.security)
  • Re: [OT] Re: LAN access while VPN is up
    ... Sure - pity the darn computer can't read my mind :-) ... > The reason it's grepping two different files is that the first is the ... munging script be self contained, and not have to carry around baggage ... > bash, the Linux Documentation Project has a HOWTO ...
    (comp.security.firewalls)
  • 5.5.2 in visual studio c++
    ... Gonna have a bash at getting a working visual studio 2005 c++ solution for v5.5.2. ... No reason why this shouldnt be possible is there? ...
    (rec.games.roguelike.moria)
  • Re: ~ expansion in bash
    ... I ran into a strange "thing" with ~ expansion in bash. ... If a word begins with an unquoted tilde character, ...
    (comp.unix.shell)