1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-10-16 11:40:46 +00:00

Compare commits

...

3 commits

Author SHA1 Message Date
Walter A. Boring IV
fcbd13d1e5
Merge 0b8a9d1de2 into f11cc8fea1 2024-09-23 09:13:09 +02:00
dependabot[bot]
f11cc8fea1
chore(deps): bump idna in /.github/workflows/dependencies (#12688)
Bumps [idna](https://github.com/kjd/idna) from 3.9 to 3.10.
- [Release notes](https://github.com/kjd/idna/releases)
- [Changelog](https://github.com/kjd/idna/blob/master/HISTORY.rst)
- [Commits](https://github.com/kjd/idna/compare/v3.9...v3.10)

---
updated-dependencies:
- dependency-name: idna
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-22 16:20:33 +02:00
Hemna
0b8a9d1de2 Added git_files_changed function
This patch adds the git library function for building a
short string that represents the output of git diff --numstat.
This gives theme designers the ability to add the
Number of files changed, number of lines added and number of
lines removed in their prompt for a git repository, while the user's
current working directory is in the git repo.

The new function supports prefix and suffix for each of the
options, files changed, lines added and lines removed.

To colorize the output, you can do something like this in your
theme file

ZSH_THEME_GIT_FILES_CHANGED_PREFIX="%{$fg[yellow]%}"
ZSH_THEME_GIT_FILES_CHANGED_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_LINES_ADDED_PREFIX="%{$fg[green]%}"
ZSH_THEME_GIT_LINES_ADDED_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_LINES_REMOVED_PREFIX="%{$fg[red]%}"
ZSH_THEME_GIT_LINES_REMOVED_SUFFIX="%{$fg[blue]%}"

For example, if there are
3 files changed, 10 lines added and no lines removed you will get
3f:10+

1 files changed, 20 lines added and 6 lines removed:
1f:20+:6-
2021-01-25 08:11:02 -05:00
2 changed files with 32 additions and 1 deletions

View file

@ -1,6 +1,6 @@
certifi==2024.8.30
charset-normalizer==3.3.2
idna==3.9
idna==3.10
PyYAML==6.0.2
requests==2.32.3
semver==3.0.2

View file

@ -349,3 +349,34 @@ function git_repo_name() {
echo ${repo_path:t}
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
}