Skip to contentSkip to conversation

prompt: do not double-discriminate detached HEAD

PATCH In review Ramkumar Ramachandra 5 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 prompt: do not double-discriminate detached HEAD

When GIT_PS1_SHOWCOLORHINTS is turned on, there is no need to put a detached HEAD within parenthesis: the color can be used to discriminate the detached HEAD.

---
For cuteness :)

 contrib/completion/git-prompt.sh | 5 ++++-
 t/t9903-bash-prompt.sh           | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
contrib/completion/git-prompt.sh +4 -1
index a81ef5a..37e66a2 100644
@@ -372,7 +372,10 @@ __git_ps1 ()
 				esac 2>/dev/null)" ||
 
 				b="$short_sha..."
-				b="($b)"
+				# if there is no color, use
+				# parenthesis to indicate that the
+				# HEAD is detached
+				test -n "${GIT_PS1_SHOWCOLORHINTS-}" || b="($b)"
 			fi
 		fi
 	fi
t/t9903-bash-prompt.sh +1 -1
index 3c3e4e8..c44b1a6 100755
@@ -450,7 +450,7 @@ test_expect_success 'prompt - bash color pc mode - branch name' '
 '
 
 test_expect_success 'prompt - bash color pc mode - detached head' '
-	printf "BEFORE: (${c_red}(%s...)${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected &&
+	printf "BEFORE: (${c_red}%s...${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected &&
 	git checkout b1^ &&
 	test_when_finished "git checkout master" &&
 	(
Signature · 1 line
1.8.3.2.737.gcbc076a.dirty
#1 lore raw
Quoted 7 lines · Ramkumar Ramachandra

When GIT_PS1_SHOWCOLORHINTS is turned on, there is no need to put a detached HEAD within parenthesis: the color can be used to discriminate the detached HEAD.

---
For cuteness :)

Personally, I'd rather see the parens kept. Not everyone sees red very well--I know several people who can't see it at all, and it keeps it consistent with non-colored output.

-John

#2 lore raw
Quoted 5 lines · John Szakmeister
Quoted 4 lines · Ramkumar Ramachandra

When GIT_PS1_SHOWCOLORHINTS is turned on, there is no need to put a detached HEAD within parenthesis: the color can be used to discriminate the detached HEAD.

Quoted 7 lines
Quoted 3 lines

---
For cuteness :)

Personally, I'd rather see the parens kept. Not everyone sees red very well--I know several people who can't see it at all, and it keeps it consistent with non-colored output.

+1; I find red on many terminal emulators to be too dark to tell, especially in a small font, from black myself.

#3 lore raw
Quoted 12 lines · Junio C Hamano
Quoted 10 lines · John Szakmeister

On Sun, Jul 7, 2013 at 8:52 AM, Ramkumar Ramachandra <[email protected]

Quoted 8 lines

wrote:
When GIT_PS1_SHOWCOLORHINTS is turned on, there is no need to put a detached HEAD within parenthesis: the color can be used to discriminate the detached HEAD.

---
For cuteness :)

Quoted 6 lines
Quoted 3 lines

Personally, I'd rather see the parens kept. Not everyone sees red very well--I know several people who can't see it at all, and it keeps it consistent with non-colored output.

+1; I find red on many terminal emulators to be too dark to tell, especially in a small font, from black myself.

+1; me too for the same reason.

#4 lore raw
In reply to Junio C Hamano
Quoted 2 lines · Junio C Hamano

+1; I find red on many terminal emulators to be too dark to tell, especially in a small font, from black myself.

It's a matter of taste anyway. I hope everyone's not going colorblind from writing too much C89 and Bourne shell ;)

Quoted 2 lines · Eduardo R. D'Avila

I think color in terminals should be used to highlight and make it easier to see textual information, not to replace them. So I would keep the parenthesis.

I largely agree, but there are a few exceptions. Most notably, have you noticed how, in addition to font-locking, scheme-mode replaces lambda with λ?

#5 lore raw
In reply to Ramkumar Ramachandra

I think color in terminals should be used to highlight and make it easier to see textual information, not to replace them. So I would keep the parenthesis.

Quoted 1 line

+ test -n "${GIT_PS1_SHOWCOLORHINTS-}" || b="($b)"

Also, the proposed change has a side-effect because color is not possible in non-pc mode, even if GIT_PS1_SHOWCOLORHINTS is defined. (Non-pc mode with GIT_PS1_SHOWCOLORHINTS defined would make the detached HEAD not be shown neither in red nor within parenthesis).

Regards,

Eduardo R. D'Avila