From dd2537bf9a06c47057bf66061100ed80809cb887 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Wed, 5 Mar 2008 11:08:44 +0100 Subject: Get the named commit-id if we are not on a working branch, or the abbreviated commit-id if neither on a nameable commit-ish. --- 01_Functions.zsh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/01_Functions.zsh b/01_Functions.zsh index b28d5a2..bf47b72 100644 --- a/01_Functions.zsh +++ b/01_Functions.zsh @@ -39,8 +39,16 @@ preprint() get_git_branch () { + # Get current working GIT branch my_git_branch="$(git-branch 2>&- | grep -E '^\* ' | cut -c3-)" - [ $my_git_branch == "(no branch)" ] && my_git_branch="$(git-log HEAD~1..HEAD --pretty=format:%h 2>&-)" + + # If not on a working GIT branch, get the named current commit-ish inside parenthesis + [ "$my_git_branch" == "(no branch)" ] &&\ + my_git_branch="$(git-show --pretty=format:%H 2>&- | head -n1 | git-name-rev --stdin 2>&- | awk '{ print $2 }')" + + # If neither on a named commit-ish, show abbreviated commit-id + [ "$my_git_branch" == "" ] &&\ + my_git_branch="($(git-show --pretty=format:%h 2>&- | head -n1)...)" echo $my_git_branch } -- cgit v1.2.3