- local output
- output=(${(f):-"$(git diff --stat --relative 2>/dev/null)"})
- if [[ ${#output} -gt 1 ]]; then
- echo changes on filesystem:
- print "${${(F)output[1,-2]}//\.\.\./…}"
- fi
- output=(${(f):-"$(git diff --cached --stat --relative 2>/dev/null)"})
- if [[ ${#output} -gt 1 ]]; then
- echo cached/staged changes:
- print "${${(F)output[1,-2]}//\.\.\./…}"
+ local COLUMNS=${COLUMNS:-80}
+ local LINES=${LINES:-25}
+
+ function output() {
+ emulate -L zsh
+ local title="$@"
+ local output=(${(f)"$(cat)"})
+
+ [[ ${#output} -ge 1 ]] || return
+
+ local statl="$(echo ${output[-1]} | sed -re 's@^\s*([0-9]+)[^,]+(, ([0-9]+) [^(]+\(([-+])\))(, ([0-9]+) [^(]+\(([-+])\))?@\1/\4\3/\7\6@')"
+
+ if [[ ${output[-2]## } = '...' ]]; then
+ print "${title} (${statl%/}, abbrev.):"
+ print "${(F)output[1,-3]}"
+ print " …"
+ else
+ print "${title} (${statl%/}):"
+ print "${(F)output[1,-2]}"
+ fi
+ }
+
+ function gitdiffstat() {
+ emulate -L zsh
+ local common_options="--stat=$((COLUMNS/2-1)),$((COLUMNS/4-2)),$(($LINES/3)) --relative"
+ eval git diff $common_options "$@" 2>/dev/null
+ }
+
+ local cached=(${(f)"$(gitdiffstat --cached | output cached)"})
+ local changed=(${(f)"$(gitdiffstat | output changed)"})
+
+ local max=${#changed}
+ [[ $max -lt ${#cached} ]] && max=${#cached}
+
+ ((max == 0)) && return
+
+ local width=$(((COLUMNS-3)/2))
+
+ if (( ${#cached} > 0 && ${#changed} > 0 )); then
+ local i
+ for (( i=1 ; i <= max ; i++ )) do
+ printf "%-${width}s │ %-${width}s\n" "${cached[$i]}" "${changed[$i]}"
+ done
+ else
+ print ${(F)cached}${(F)changed}