[#221] Do not format undefined zstyles
This commit is contained in:
parent
f3ae9dd82c
commit
5306bab7ce
@ -206,41 +206,93 @@ function git-info {
|
||||
# Used to abort and turn git-info off on SIGINT.
|
||||
_git_info_executing=true
|
||||
|
||||
# Use porcelain status for easy parsing.
|
||||
status_cmd='git status --porcelain'
|
||||
|
||||
# Gets the remote name.
|
||||
remote_cmd='git rev-parse --symbolic-full-name --verify HEAD@{upstream}'
|
||||
|
||||
# Gets the commit difference counts between local and remote.
|
||||
ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}'
|
||||
|
||||
# Ignore submodule status.
|
||||
zstyle -s ':prezto:module:git:status:ignore' submodules 'ignore_submodules'
|
||||
if [[ -n "$ignore_submodules" ]]; then
|
||||
status_cmd+=" --ignore-submodules=${ignore_submodules}"
|
||||
fi
|
||||
|
||||
# Format commit.
|
||||
zstyle -s ':prezto:module:git:info:commit' format 'commit_format'
|
||||
if [[ -n "$commit_format" ]]; then
|
||||
commit="$(git rev-parse HEAD 2> /dev/null)"
|
||||
if [[ -n "$commit" ]]; then
|
||||
zstyle -s ':prezto:module:git:info:commit' format 'commit_format'
|
||||
zformat -f commit_formatted "$commit_format" "c:$commit"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Format stashed.
|
||||
if [[ -f "$(git-dir)/refs/stash" ]]; then
|
||||
stashed="$(git stash list 2> /dev/null | wc -l | awk '{print $1}')"
|
||||
zstyle -s ':prezto:module:git:info:stashed' format 'stashed_format'
|
||||
if [[ -n "$stashed_format" && -f "$(git-dir)/refs/stash" ]]; then
|
||||
stashed="$(git stash list 2> /dev/null | wc -l | awk '{print $1}')"
|
||||
if [[ -n "$stashed" ]]; then
|
||||
zformat -f stashed_formatted "$stashed_format" "S:$stashed"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Format action.
|
||||
zstyle -s ':prezto:module:git:info:action' format 'action_format'
|
||||
if [[ -n "$action_format" ]]; then
|
||||
action="$(_git-action)"
|
||||
if [[ -n "$action" ]]; then
|
||||
zstyle -s ':prezto:module:git:info:action' format 'action_format'
|
||||
zformat -f action_formatted "$action_format" "s:$action"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Get the branch.
|
||||
branch="${$(git symbolic-ref HEAD 2> /dev/null)#refs/heads/}"
|
||||
|
||||
# Format branch.
|
||||
zstyle -s ':prezto:module:git:info:branch' format 'branch_format'
|
||||
if [[ -n "$branch" && -n "$branch_format" ]]; then
|
||||
zformat -f branch_formatted "$branch_format" "b:$branch"
|
||||
fi
|
||||
|
||||
# Format position.
|
||||
zstyle -s ':prezto:module:git:info:position' format 'position_format'
|
||||
if [[ -z "$branch" && -n "$position_format" ]]; then
|
||||
position="$(git describe --contains --all HEAD 2> /dev/null)"
|
||||
if [[ -n "$position" ]]; then
|
||||
zformat -f position_formatted "$position_format" "p:$position"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Format remote.
|
||||
zstyle -s ':prezto:module:git:info:remote' format 'remote_format'
|
||||
if [[ -n "$branch" && -n "$remote_format" ]]; then
|
||||
# Gets the remote name.
|
||||
remote_cmd='git rev-parse --symbolic-full-name --verify HEAD@{upstream}'
|
||||
remote="${$(${(z)remote_cmd} 2> /dev/null)##refs/remotes/}"
|
||||
if [[ -n "$remote" ]]; then
|
||||
zformat -f remote_formatted "$remote_format" "R:$remote"
|
||||
fi
|
||||
fi
|
||||
|
||||
zstyle -s ':prezto:module:git:info:ahead' format 'ahead_format'
|
||||
zstyle -s ':prezto:module:git:info:behind' format 'behind_format'
|
||||
if [[ -n "$branch" && ( -n "$ahead_format" || -n "$behind_format" ) ]]; then
|
||||
# Gets the commit difference counts between local and remote.
|
||||
ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}'
|
||||
|
||||
# Get ahead and behind counts.
|
||||
ahead_and_behind="$(${(z)ahead_and_behind_cmd} 2> /dev/null)"
|
||||
|
||||
# Format ahead.
|
||||
if [[ -n "$ahead_format" ]]; then
|
||||
ahead="$ahead_and_behind[(w)1]"
|
||||
if (( ahead > 0 )); then
|
||||
zformat -f ahead_formatted "$ahead_format" "A:$ahead"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Format behind.
|
||||
if [[ -n "$behind_format" ]]; then
|
||||
behind="$ahead_and_behind[(w)2]"
|
||||
if (( behind > 0 )); then
|
||||
zformat -f behind_formatted "$behind_format" "B:$behind"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Use porcelain status for easy parsing.
|
||||
status_cmd="git status --porcelain --ignore-submodules=${ignore_submodules:-none}"
|
||||
|
||||
# Get current status.
|
||||
while IFS=$'\n' read line; do
|
||||
@ -256,82 +308,44 @@ function git-info {
|
||||
(( dirty++ ))
|
||||
done < <(${(z)status_cmd} 2> /dev/null)
|
||||
|
||||
# Format branch.
|
||||
branch="${$(git symbolic-ref -q HEAD)##refs/heads/}"
|
||||
if [[ -n "$branch" ]]; then
|
||||
zstyle -s ':prezto:module:git:info:branch' format 'branch_format'
|
||||
zformat -f branch_formatted "$branch_format" "b:$branch"
|
||||
|
||||
# Format remote.
|
||||
remote="${$(${(z)remote_cmd} 2> /dev/null)##refs/remotes/}"
|
||||
if [[ -n "$remote" ]]; then
|
||||
zstyle -s ':prezto:module:git:info:remote' format 'remote_format'
|
||||
zformat -f remote_formatted "$remote_format" "R:$remote"
|
||||
|
||||
# Get ahead and behind counts.
|
||||
ahead_and_behind="$(${(z)ahead_and_behind_cmd} 2> /dev/null)"
|
||||
|
||||
# Format ahead.
|
||||
ahead="$ahead_and_behind[(w)1]"
|
||||
if (( $ahead > 0 )); then
|
||||
zstyle -s ':prezto:module:git:info:ahead' format 'ahead_format'
|
||||
zformat -f ahead_formatted "$ahead_format" "A:$ahead"
|
||||
fi
|
||||
|
||||
# Format behind.
|
||||
behind="$ahead_and_behind[(w)2]"
|
||||
if (( $behind > 0 )); then
|
||||
zstyle -s ':prezto:module:git:info:behind' format 'behind_format'
|
||||
zformat -f behind_formatted "$behind_format" "B:$behind"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# Format position.
|
||||
position="$(git describe --contains --all HEAD 2> /dev/null)"
|
||||
if [[ -n "$position" ]]; then
|
||||
zstyle -s ':prezto:module:git:info:position' format 'position_format'
|
||||
zformat -f position_formatted "$position_format" "p:$position"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Format added.
|
||||
if (( $added > 0 )); then
|
||||
if (( added > 0 )); then
|
||||
zstyle -s ':prezto:module:git:info:added' format 'added_format'
|
||||
zformat -f added_formatted "$added_format" "a:$added_format"
|
||||
fi
|
||||
|
||||
# Format deleted.
|
||||
if (( $deleted > 0 )); then
|
||||
if (( deleted > 0 )); then
|
||||
zstyle -s ':prezto:module:git:info:deleted' format 'deleted_format'
|
||||
zformat -f deleted_formatted "$deleted_format" "d:$deleted_format"
|
||||
fi
|
||||
|
||||
# Format modified.
|
||||
if (( $modified > 0 )); then
|
||||
if (( modified > 0 )); then
|
||||
zstyle -s ':prezto:module:git:info:modified' format 'modified_format'
|
||||
zformat -f modified_formatted "$modified_format" "m:$modified"
|
||||
fi
|
||||
|
||||
# Format renamed.
|
||||
if (( $renamed > 0 )); then
|
||||
if (( renamed > 0 )); then
|
||||
zstyle -s ':prezto:module:git:info:renamed' format 'renamed_format'
|
||||
zformat -f renamed_formatted "$renamed_format" "r:$renamed"
|
||||
fi
|
||||
|
||||
# Format unmerged.
|
||||
if (( $unmerged > 0 )); then
|
||||
if (( unmerged > 0 )); then
|
||||
zstyle -s ':prezto:module:git:info:unmerged' format 'unmerged_format'
|
||||
zformat -f unmerged_formatted "$unmerged_format" "U:$unmerged"
|
||||
fi
|
||||
|
||||
# Format untracked.
|
||||
if (( $untracked > 0 )); then
|
||||
if (( untracked > 0 )); then
|
||||
zstyle -s ':prezto:module:git:info:untracked' format 'untracked_format'
|
||||
zformat -f untracked_formatted "$untracked_format" "u:$untracked"
|
||||
fi
|
||||
|
||||
# Format dirty and clean.
|
||||
if (( $dirty > 0 )); then
|
||||
if (( dirty > 0 )); then
|
||||
zstyle -s ':prezto:module:git:info:dirty' format 'dirty_format'
|
||||
zformat -f dirty_formatted "$dirty_format" "D:$dirty"
|
||||
else
|
||||
@ -342,21 +356,21 @@ function git-info {
|
||||
zstyle -a ':prezto:module:git:info:keys' format 'info_formats'
|
||||
for info_format in ${(k)info_formats}; do
|
||||
zformat -f REPLY "$info_formats[$info_format]" \
|
||||
"a:$added_formatted" \
|
||||
"A:$ahead_formatted" \
|
||||
"B:$behind_formatted" \
|
||||
"D:$dirty_formatted" \
|
||||
"R:$remote_formatted" \
|
||||
"S:$stashed_formatted" \
|
||||
"U:$unmerged_formatted" \
|
||||
"a:$added_formatted" \
|
||||
"b:$branch_formatted" \
|
||||
"C:$clean_formatted" \
|
||||
"c:$commit_formatted" \
|
||||
"d:$deleted_formatted" \
|
||||
"D:$dirty_formatted" \
|
||||
"m:$modified_formatted" \
|
||||
"p:$position_formatted" \
|
||||
"R:$remote_formatted" \
|
||||
"r:$renamed_formatted" \
|
||||
"s:$action_formatted" \
|
||||
"S:$stashed_formatted" \
|
||||
"U:$unmerged_formatted" \
|
||||
"u:$untracked_formatted"
|
||||
git_info[$info_format]="$REPLY"
|
||||
done
|
||||
|
Reference in New Issue
Block a user