From: Andrew Sayers <andrew-git@pileofstuff.org>
To: Sebastien Douche <sdouche@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Add colors to the prompt for status indicators
Date: Sun, 14 Nov 2010 20:50:10 +0000 [thread overview]
Message-ID: <4CE04B82.1040804@pileofstuff.org> (raw)
In-Reply-To: <AANLkTi=ZdR4_reQgxL+xRaFE=SaqBYAWTrEuGEbLGynt@mail.gmail.com>
Sorry for the delayed response to this one - I'm afraid it's the usual
work excuse :)
Non-printing characters need to be surrounded by \[ and \] for bash to
calculate line lengths correctly. So far as I can tell, this has to be
in PS1 itself - bash doesn't recognise it if it's included in a script.
To see the problem, do this:
OLD_PS1="$PS1"
PS1="\033[0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0m>"
Then hold down any key - you should see some weird line-wrapping
behaviour a little way before the edge of your terminal. To get your
old terminal back:
PS1="$OLD_PS1"
To see what happens when the "\[" characters are embedded in a script:
foo() {
echo -e "\[\033[;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0m\]"
}
PS1='$(foo)>'
The "\[" and "\]" are represented literally in your terminal, and the
line-wrapping still occurs.
It's possible to work around this for a whole script:
foo() {
echo -e "\033[;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0m"
}
PS1='\[$(foo)'\]>'
As a fan of colourful prompts, I'd be very happy if you found a way
around this for parts of a script. But as a fan of fast prompts, I'd
prefer not to call __git_ps1 more than once :)
- Andrew
next prev parent reply other threads:[~2010-11-14 20:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-31 4:14 Add colors to the prompt for status indicators Sebastien Douche
2010-10-31 6:26 ` Kevin Ballard
2010-11-14 20:50 ` Andrew Sayers [this message]
2010-11-15 22:52 ` Kevin Ballard
2010-11-15 23:14 ` Kevin Ballard
2010-11-16 8:11 ` Sebastien Douche
2010-11-16 9:07 ` Kevin Ballard
2010-11-16 10:43 ` Michael J Gruber
2010-11-16 10:49 ` Kevin Ballard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CE04B82.1040804@pileofstuff.org \
--to=andrew-git@pileofstuff.org \
--cc=git@vger.kernel.org \
--cc=sdouche@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.