Added support for ignoring Git submodules.

This commit is contained in:
Sorin Ionescu 2012-02-03 19:12:47 -05:00
parent 0829f921db
commit 3f3b2328f9
2 changed files with 20 additions and 1 deletions

View file

@ -147,6 +147,9 @@ function git-info() {
local rprompt local rprompt
local git_info_var local git_info_var
local -A git_info_vars local -A git_info_vars
local status_cmd
local ignore_submodule
local ignore_submodule_when
# Clean up previous Git info. # Clean up previous Git info.
unset git_prompt_info unset git_prompt_info
@ -176,6 +179,16 @@ function git-info() {
# Used to abort and turn git-info off on SIGINT. # Used to abort and turn git-info off on SIGINT.
_git_info_executing=true _git_info_executing=true
# Use short status for easy parsing.
status_cmd='git status --short --branch'
# Ignore submodule status.
zstyle -b ':omz:plugin:git:prompt:ignore' submodule ignore_submodule
zstyle -s ':omz:plugin:git:prompt:ignore:submodule' when ignore_submodule_when
if is-true "$ignore_submodule"; then
status_cmd+=" --ignore-submodules=${ignore_submodule_when:-all}"
fi
# Get commit. # Get commit.
commit="$(git rev-parse HEAD 2> /dev/null)" commit="$(git rev-parse HEAD 2> /dev/null)"
@ -248,7 +261,7 @@ function git-info() {
[[ "$line" == UU\ * ]] && (( unmerged++ )) [[ "$line" == UU\ * ]] && (( unmerged++ ))
[[ "$line" == \?\?\ * ]] && (( untracked++ )) [[ "$line" == \?\?\ * ]] && (( untracked++ ))
fi fi
done < <(git status --short --branch 2> /dev/null) done < <("${(z)status_cmd}" 2> /dev/null)
# Format branch. # Format branch.
zstyle -s ':omz:plugin:git:prompt' branch branch_format zstyle -s ':omz:plugin:git:prompt' branch branch_format

View file

@ -56,3 +56,9 @@ zstyle ':omz:plugin:git:prompt' prompt ' git:(%b %D%C)'
# Right prompt. # Right prompt.
zstyle ':omz:plugin:git:prompt' rprompt '' zstyle ':omz:plugin:git:prompt' rprompt ''
# Ignore submodule.
zstyle ':omz:plugin:git:prompt:ignore' submodule 'no'
# Ignore submodule when it is 'dirty', 'untracked', 'all', or 'none'.
zstyle ':omz:plugin:git:prompt:ignore:submodule' when 'all'