1
0
Fork 0

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
pull/39/head
Colin Hebert 13 years ago
parent bf27bc1e3b
commit 6955252281

@ -145,6 +145,10 @@ function git-info {
local deleted=0 local deleted=0
local deleted_format local deleted_format
local deleted_formatted local deleted_formatted
local describe
local describe_cmd
local describe_format
local describe_formatted
local dirty=0 local dirty=0
local dirty_format local dirty_format
local dirty_formatted local dirty_formatted
@ -213,6 +217,9 @@ function git-info {
# Gets the commit difference counts between local and remote. # Gets the commit difference counts between local and remote.
ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}' 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. # Ignore submodule status.
zstyle -b \ zstyle -b \
':omz:plugin:git:prompt:ignore' submodule 'ignore_submodule' ':omz:plugin:git:prompt:ignore' submodule 'ignore_submodule'
@ -286,6 +293,13 @@ function git-info {
zformat -f behind_formatted "$behind_format" "B:$behind" zformat -f behind_formatted "$behind_format" "B:$behind"
fi fi
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 fi
# Format added. # Format added.
@ -349,6 +363,7 @@ function git-info {
"c:$commit_formatted" \ "c:$commit_formatted" \
"d:$deleted_formatted" \ "d:$deleted_formatted" \
"D:$dirty_formatted" \ "D:$dirty_formatted" \
"i:$describe_formatted" \
"m:$modified_formatted" \ "m:$modified_formatted" \
"R:$remote_formatted" \ "R:$remote_formatted" \
"r:$renamed_formatted" \ "r:$renamed_formatted" \

@ -29,6 +29,9 @@ zstyle ':omz:plugin:git:prompt' deleted 'deleted:%d'
# %D - Indicator to notify of dirty files. # %D - Indicator to notify of dirty files.
zstyle ':omz:plugin:git:prompt' dirty 'dirty:%D' 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. # %m - Indicator to notify of modified files.
zstyle ':omz:plugin:git:prompt' modified 'modified:%m' zstyle ':omz:plugin:git:prompt' modified 'modified:%m'

Loading…
Cancel
Save