bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble with PS1 special characters between \[ and \]


From: Bob Proulx
Subject: Re: Trouble with PS1 special characters between \[ and \]
Date: Fri, 5 Nov 2010 21:44:25 -0600
User-agent: Mutt/1.5.20 (2009-06-14)

Lluís Batlle i Rossell wrote:
> I don't think this problem is related to any recent bash version
> only. I've seen this since years I think.
> 
> Nevertheless I'm using GNU bash, version 4.0.17(1)-release
> (x86_64-unknown-linux-gnu) now.

I am using 4.1.5(1)-release and I could not recreate your problem.

> My PS1 uses the "Change window title" sequence, to set the xterm
> window title to something close to the prompt text. Hence my PS1 is:
> 
> PS1='\[\033]2;\h:\u:\w\007\]\n\[\033[1;31m\][\u@\h:\w]\$\[\033[0m\] '

This is something that you may have better luck if you put the window
title setting sequences into PROMPT_COMMAND instead.  Then you would
not need to use the \[...\] around the non-visible parts of PS1 since
they won't be there at all.  That would leave just your color changes
needing them.  This may be enough to avoid the problem you are having
regardless of its source.

The PROMPT_COMMAND won't expand the PS1 \u \h \w sequences though and
you would want to use the full variable names for them.  I have had
the following in my .bashrc for a long time.

  case $TERM in
    xterm*)
      PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD/$HOME/~}\007"'
      ;;
  esac

Then add something like this for your adjusted PS1 prompt.

  PS1='\n\[\033[1;31m\][\u@\h:\w]\$\[\033[0m\] '

That leading \n gives me pause though...

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]