Skip to content

Commit

Permalink
[Fix sorin-ionescu#42] Count dirty files in Git repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinHebert authored and sorin-ionescu committed Mar 21, 2012
1 parent 4abee19 commit 720a48c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions plugins/git/functions/git-info
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ function git-info() {
local deleted=0
local deleted_format
local deleted_formatted
local dirty
local dirty=0
local dirty_format
local dirty_formatted
local line_number=0
local modified=0
Expand Down Expand Up @@ -277,21 +278,14 @@ function git-info() {
branch="$match[1]"
fi
else
# Format dirty.
if [[ -z "$dirty" ]]; then
zstyle -s ':omz:plugin:git:prompt' dirty 'dirty_formatted'
if [[ -z "$dirty_formatted" ]]; then
unset clean_formatted
fi
fi

# Count: added/deleted/modified/renamed/unmerged/untracked
# Count added, deleted, modified, renamed, unmerged, untracked, dirty.
[[ "$line" == (((A|M|D|T) )|(AD|AM|AT|MM))\ * ]] && (( added++ ))
[[ "$line" == ( D|AD)\ * ]] && (( deleted++ ))
[[ "$line" == (( (M|T))|(AM|AT|MM))\ * ]] && (( modified++ ))
[[ "$line" == R\ \ * ]] && (( renamed++ ))
[[ "$line" == UU\ * ]] && (( unmerged++ ))
[[ "$line" == \?\?\ * ]] && (( untracked++ ))
(( dirty++ ))
fi
done < <("${(z)status_cmd}" 2>/dev/null)

Expand Down Expand Up @@ -359,6 +353,13 @@ function git-info() {
zformat -f untracked_formatted "$untracked_format" "u:$untracked"
fi

# Format dirty.
if (( $dirty > 0 )); then
zstyle -s ':omz:plugin:git:prompt' dirty 'dirty_format'
zformat -f dirty_formatted "$dirty_format" "D:$dirty"
unset clean_formatted
fi

# Format prompts.
zstyle -s ':omz:plugin:git:prompt' prompt 'prompt_format'
zstyle -s ':omz:plugin:git:prompt' rprompt 'rprompt_format'
Expand Down
4 changes: 2 additions & 2 deletions plugins/git/style.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ zstyle ':omz:plugin:git:prompt' commit 'commit:%c'
# %d - Indicator to notify of deleted files.
zstyle ':omz:plugin:git:prompt' deleted 'deleted:%d'

# %D - Indicator to notify of dirty branch.
zstyle ':omz:plugin:git:prompt' dirty 'dirty'
# %D - Indicator to notify of dirty files.
zstyle ':omz:plugin:git:prompt' dirty 'dirty:%D'

# %m - Indicator to notify of modified files.
zstyle ':omz:plugin:git:prompt' modified 'modified:%m'
Expand Down

0 comments on commit 720a48c

Please sign in to comment.