1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-10-16 11:40:46 +00:00
This commit is contained in:
Walter A. Boring IV 2024-09-23 17:52:45 +02:00 committed by GitHub
commit 25f562e0b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -349,3 +349,34 @@ function git_repo_name() {
echo ${repo_path:t} echo ${repo_path:t}
fi fi
} }
# Outputs 3 stats for git repo
# 1) number of files changed,
# 2) the total number of lines added
# 3) total number of lines removed
#
# Example
# 3f:69+:6-
function git_files_changed() {
local -i files=0
local -i insertions=0
local -i deletions=0
local raw=$(command git diff --numstat 2>/dev/null) || return 0
if [[ -n $raw ]]; then
echo $raw | while IFS= read -r line; do
local -i d=$line[(w)2]
local -i i=$line[(w)1]
insertions+=i
deletions+=d
files+=1
done
local output="$ZSH_THEME_GIT_FILES_CHANGED_PREFIX${files}f$ZSH_THEME_GIT_FILES_CHANGED_SUFFIX"
if (( $insertions > 0 )); then
output="$output:$ZSH_THEME_GIT_LINES_ADDED_PREFIX${insertions}+$ZSH_THEME_GIT_LINES_ADDED_SUFFIX"
fi
if (( $deletions > 0 )); then
output="$output:$ZSH_THEME_GIT_LINES_REMOVED_PREFIX${deletions}-$ZSH_THEME_GIT_LINES_REMOVED_SUFFIX"
fi
echo $output
fi
}