Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
From: Piotr Krukowiecki <hidden>
Date: 2016-06-15 22:55:27
Re-sending mail. On Wed, Nov 28, 2012 at 7:02 PM, Piotr Krukowiecki [off-list ref] wrote:
On Wed, Nov 28, 2012 at 2:20 PM, Simon Oosthoek [off-list ref] wrote:quoted
* Piotr Krukowiecki [off-list ref] [2012-11-28 11:03:29 +0100]:quoted
Hi, when I set PROMPT_COMMAND to __git_ps1 I get a space at the beginning:Is your setting?: PROMPT_COMMAND=__git_ps1That's rightquoted
I believe you need to give 2 parameters in order to use it in PROMPT_COMMAND mode.Are you sure? git-prompt.sh says: # 3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1 # To customize the prompt, provide start/end arguments # PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' I interpret this as: if you don't want to customize the prompt, the simple "PROMPT_COMMAND=__git_ps1" is enough.quoted
quoted
(master)pkruk@foobar ~/dir$ ^ space Is there a reason for this? It looks like a waste of space. If I'm not in git repository I don't have the space: pkruk@foobar ~/other$ I noticed the space is explicitly specified in printf_format in git-prompt.sh. Is it needed? If I remove it, everything seems to work fine (no leading space)...--- /usr/local/src/git/git/contrib/completion/git-prompt.sh 2012-11-2810:27:05.728939201 +0100+++ /home/pkruk/.git-prompt.sh 2012-11-28 10:52:56.852629745 +0100@@ -218,7 +218,7 @@ __git_ps1 () local detached=no local ps1pc_start='\u@\h:\w ' local ps1pc_end='\$ ' - local printf_format=' (%s)' + local printf_format='(%s)' case "$#" in 2) pcmode=yesThese last 2 lines say: if 2 arguments are given, use pcmode. Otherwise you get command-subtitution mode, which gives weird effects when being called from PROMPT_COMMAND.Still, it seems to work with above "patch"..
-- Piotr Krukowiecki