summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Hiegel <hugues@hiegel.fr>2008-03-05 11:08:44 +0100
committerHugues Hiegel <hugues@hiegel.fr>2008-03-07 14:15:22 +0100
commitdd2537bf9a06c47057bf66061100ed80809cb887 (patch)
tree7840a6e01cbb21c8011caa3145c3ff0d9ba432f3
parent3f37681668bfe77223577925d4fb0c9302b44782 (diff)
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.
-rw-r--r--01_Functions.zsh10
1 files changed, 9 insertions, 1 deletions
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
}