bash completion: add space between branch name and status flags
PATCH 1/1 bash completion: add space between branch name and status flags
Hello Shawn, hello git list members,
Wouldn't it improve the readability of the bash prompt, if there would be a space between the branch name and the status flags (dirty, stash, untracked)?
--- contrib/completion/git-completion.bash | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
contrib/completion/git- renamed from contrib/completion/git-completion.bash +0 -0
completion.bash
index bd66639..407176b 100755
contrib/completion/git-completion.bash +4 -2
@@ -169,10 +169,12 @@ __git_ps1 () fi fi + local f="$w$i$s$u$r" + f=${f:+ $f} if [ -n "${1-}" ]; then - printf "$1" "$c${b##refs/heads/}$w$i$s$u$r" + printf "$1" "$c${b##refs/heads/}$f" else - printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r" + printf " (%s)" "$c${b##refs/heads/}$f" fi fi }
Signature · 9 lines
1.6.4.2 Roman -- Roman Fietze Telemotive AG Büro Mühlhausen Breitwiesen 73347 Mühlhausen Tel.: +49(0)7335/18493-45 http://www.telemotive.de
Quoted 5 lines · Roman Fietze
Hello Shawn, hello git list members,
Wouldn't it improve the readability of the bash prompt, if there would be a space between the branch name and the status flags (dirty, stash, untracked)?
Perhaps.
Quoted 11 lines
Signed-off-by Roman Fietze <[email protected]>--- contrib/completion/git-completion.bash | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)contrib/completion/git- renamed from contrib/completion/git-completion.bash +0
-0completion.bash
index bd66639..407176b 100755
contrib/completion/git-completion.bash __git_ps1 () · line 172
Quoted 4 lines
contrib/completion/git-completion.bash +1
-0@@ -169,10 +169,12 @@ __git_ps1 () fi fi + local f="$w$i$s$u$r"
I think this line and the two changes to printf below is a big improvement (unless we are using f for something else---I didn't look). But I think the next line is wrong.
contrib/completion/git-completion.bash __git_ps1 () · line 173
Quoted 1 line
contrib/completion/git-completion.bash +1
-0+ f=${f:+ $f}
The $r string is designed to be used as suffix from the beginning and always has "|" in front of it as a delimiter, so if there is no w/i/s/u (and I suspect many people do not use GIT_PS1_SHOWDIRTYSTATE and friends, and these are _always_ empty for them) the above will begin with "|". There is no need to steal one column from a typeable width from the command line in such a case.
contrib/completion/git-completion.bash __git_ps1 () · line 180
Quoted 9 lines
contrib/completion/git-completion.bash +2
-2if [ -n "${1-}" ]; then - printf "$1" "$c${b##refs/heads/}$w$i$s$u$r" + printf "$1" "$c${b##refs/heads/}$f" else - printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r" + printf " (%s)" "$c${b##refs/heads/}$f" fi fi }
To implement your stated goal (dirty/stash/untracked), you probably want to do this instead...
local f="$w$i$s$u"
f="${f:+ $f}$r"Junio, could you tell us what happened to this thread?
In response to a patch from Roman Fietze to outline a better way to do it. Nothing happened.
Quoted 4 lines · Nanako Shiraishi
Junio, could you tell us what happened to this thread?
In response to a patch from Roman Fietze to outline a better way to do it. Nothing happened.
Junio responded with a suggestion on how to improve the patch when GIT_PS1_SHOWDIRTYSTATE was not set, but Roman Fietze didn't send a revised patch, so it got dropped.
Here is the revised patch, Junio, still think its a good idea?
--8<--
From: Roman Fietze <[email protected]>
Subject: [PATCH] bash completion: add space between branch name and status flags
Improve the readability of the bash prompt by adding a space between the branch name and the status flags (dirty, stash, untracked).
--- contrib/completion/git-completion.bash | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
contrib/completion/git-completion.bash +4 -2
@@ -163,10 +163,12 @@ __git_ps1 () fi fi + local f="$w$i$s$u" + f="${f:+ $f}$r" if [ -n "${1-}" ]; then - printf "$1" "$c${b##refs/heads/}$w$i$s$u$r" + printf "$1" "$c${b##refs/heads/}$f" else - printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r" + printf " (%s)" "$c${b##refs/heads/}$f" fi fi }
Signature · 5 lines
1.6.6.307.gba67 -- Shawn.
Quoted 11 lines · Shawn O. Pearce
Quoted 4 lines · Nanako Shiraishi
Junio, could you tell us what happened to this thread?
In response to a patch from Roman Fietze to outline a better way to do it. Nothing happened.
Junio responded with a suggestion on how to improve the patch when
GIT_PS1_SHOWDIRTYSTATEwas not set, but Roman Fietze didn't send a revised patch, so it got dropped.Here is the revised patch, Junio, still think its a good idea?
Thanks for following up.
As I don't use $[wisu] myself, I don't have a very strong opinion either way, but the user has spent cycles to compute them, so we'd better present them in a way that is easier to read, I guess.
Quoted 7 lines
contrib/completion/git-completion.bash +0
-0@@ -163,10 +163,12 @@ __git_ps1 () fi fi
contrib/completion/git-completion.bash __git_ps1 () · line 172
Quoted 10 lines
contrib/completion/git-completion.bash +4
-2+ local f="$w$i$s$u" + f="${f:+ $f}$r" if [ -n "${1-}" ]; then - printf "$1" "$c${b##refs/heads/}$w$i$s$u$r" + printf "$1" "$c${b##refs/heads/}$f" else - printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r" + printf " (%s)" "$c${b##refs/heads/}$f" fi
I notice that printf argument look very similar. Maybe we want to do something like
printf "${1:-" (%s)"}" ...to avoid duplication?
PATCH 1/1 bash completion: add space between branch name and status flags
Improve the readability of the bash prompt by adding a space between the branch name and the status flags (dirty, stash, untracked).
While we are cleaning up this section of code, the two cases for formatting the prompt are identical except for the format string, so make them the same.
---
Quoted 6 lines · Junio C Hamano
I notice that printf argument look very similar. Maybe we want to do something like
printf "${1:-" (%s)"}" ...to avoid duplication?
Ack.
Because its rather far from the original poster's patch, I've taken blame for it.
contrib/completion/git-completion.bash | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
contrib/completion/git-completion.bash +3 -5
@@ -163,11 +163,9 @@ __git_ps1 () fi fi - if [ -n "${1-}" ]; then - printf "$1" "$c${b##refs/heads/}$w$i$s$u$r" - else - printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r" - fi + local f="$w$i$s$u" + f="${f:+ $f}$r" + printf "${1:- (%s)}" "$c${b##refs/heads/}$f" fi }
Signature · 4 lines
1.6.6.325.g6f5f -- Shawn.
Hello Shawn,
Quoted 2 lines · On Wednesday 30 December 2009 15:57:51 Shawn O. Pearce wrote:
... but Roman Fietze didn't send
a revised patch, so it got dropped
Sorry about that, but our Notes "spam filter" has been eating important mail again.
I'l check the version as proposed by you as soon as I'm back.
Roman
Signature · 3 lines
Roman Fietze Telemotive AG Büro Mühlhausen Breitwiesen 73347 Mühlhausen Tel.: +49(0)7335/18493-45 http://www.telemotive.de