From 695525228161127a76e8db44404387dfc5cd2d9e Mon Sep 17 00:00:00 2001 From: Colin Hebert Date: Wed, 14 Mar 2012 22:38:32 +0000 Subject: [PATCH] Add a style that shows a commit relative to a tag/branch Add a new style in the git plugin to get a commit name based on the closest branch/tag --- plugins/git/functions/git-info | 15 +++++++++++++++ plugins/git/style.zsh | 3 +++ 2 files changed, 18 insertions(+) diff --git a/plugins/git/functions/git-info b/plugins/git/functions/git-info index 7efc2ea7..214935f8 100644 --- a/plugins/git/functions/git-info +++ b/plugins/git/functions/git-info @@ -145,6 +145,10 @@ function git-info { local deleted=0 local deleted_format local deleted_formatted + local describe + local describe_cmd + local describe_format + local describe_formatted local dirty=0 local dirty_format local dirty_formatted @@ -213,6 +217,9 @@ function git-info { # Gets the commit difference counts between local and remote. ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}' + # Use describe for approximative branch naming + describe_cmd='git describe --contains --all HEAD' + # Ignore submodule status. zstyle -b \ ':omz:plugin:git:prompt:ignore' submodule 'ignore_submodule' @@ -286,6 +293,13 @@ function git-info { zformat -f behind_formatted "$behind_format" "B:$behind" fi fi + else + # Format describe. + describe=$(${(z)describe_cmd} 2>/dev/null) + if [[ -n "$describe" ]]; then + zstyle -s ':omz:plugin:git:prompt' describe 'describe_format' + zformat -f describe_formatted "$describe_format" "i:$describe" + fi fi # Format added. @@ -349,6 +363,7 @@ function git-info { "c:$commit_formatted" \ "d:$deleted_formatted" \ "D:$dirty_formatted" \ + "i:$describe_formatted" \ "m:$modified_formatted" \ "R:$remote_formatted" \ "r:$renamed_formatted" \ diff --git a/plugins/git/style.zsh b/plugins/git/style.zsh index 29ac1f6a..359650c3 100644 --- a/plugins/git/style.zsh +++ b/plugins/git/style.zsh @@ -29,6 +29,9 @@ zstyle ':omz:plugin:git:prompt' deleted 'deleted:%d' # %D - Indicator to notify of dirty files. zstyle ':omz:plugin:git:prompt' dirty 'dirty:%D' +# %i - Closest branch/tag to the commit +zstyle ':omz:plugin:git:prompt' describe '(%i)' + # %m - Indicator to notify of modified files. zstyle ':omz:plugin:git:prompt' modified 'modified:%m'