All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
To: Simon Oosthoek <s.oosthoek@xs4all.nl>
Cc: Andrew Schwartzmeyer <andrew@schwartzmeyer.com>,
	git@vger.kernel.org, erdavila@gmail.com
Subject: Re: [PATCH] git-prompt: make colors available in custom prompts
Date: Mon, 02 May 2016 09:15:55 +0200	[thread overview]
Message-ID: <87oa8p0w2c.fsf@linux-m68k.org> (raw)
In-Reply-To: <5726F647.6030805@xs4all.nl> (Simon Oosthoek's message of "Mon, 2 May 2016 08:40:07 +0200")

Simon Oosthoek <s.oosthoek@xs4all.nl> writes:

> Hi Andrew
>
> sorry, I only noticed your request this morning...
>
> On 22/04/16 07:00, Andrew Schwartzmeyer wrote:
>> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
>> index f18aedc73..ffe79168c 100644
>> --- a/contrib/completion/git-prompt.sh
>> +++ b/contrib/completion/git-prompt.sh
>> @@ -12,8 +12,8 @@
>>   #        source ~/.git-prompt.sh
>>   #    3a) Change your PS1 to call __git_ps1 as
>>   #        command-substitution:
>> -#        Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
>> -#        ZSH:  setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
>> +#        Bash: PS1="[\u@\h \W$(__git_ps1 ' (%s)')]\$ "
>> +#        ZSH:  setopt PROMPT_SUBST ; PS1="[%n@%m %c$(__git_ps1 ' (%s)')]\$ "
>
> I haven't tested this at all, but when using double quotes, you need to at
> least check all the escapings, like \$ should probably be: \\\$ when used
> in double quotes.

By using double quotes the command subsititution is expanded when PS1 is
set, which makes it pretty useless.

> The original reason for not using colors in command substitution mode was
> that the prompt string length was not calculated correctly by bash and it
> messed up the commandline with very long commands (relative to the
> terminal width), when browsing the command history.

If you want to include control characters in the prompt that don't
contribute to the length you have to enclose them in \[ \].  The problem
is that \[ \] are processed before embedded command substitutions are
expanded, thus they cannot produce such control characters.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

      reply	other threads:[~2016-05-02  7:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1461301201-92142-1-git-send-email-andrew@schwartzmeyer.com>
2016-05-02  6:40 ` [PATCH] git-prompt: make colors available in custom prompts Simon Oosthoek
2016-05-02  7:15   ` Andreas Schwab [this message]

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=87oa8p0w2c.fsf@linux-m68k.org \
    --to=schwab@linux-m68k.org \
    --cc=andrew@schwartzmeyer.com \
    --cc=erdavila@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=s.oosthoek@xs4all.nl \
    /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.