From a008308267bb8e0042b1f8bf7606902eb4980b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Grill?= Date: Sun, 12 Feb 2023 13:14:16 +0100 Subject: [PATCH] Change the oneline option to a tebular version in the git summary (#1031) Co-authored-by: guenthgr --- Commands.md | 11 ++++-- bin/git-summary | 88 +++++++++++++++++++++++++++----------------- man/git-summary.1 | 28 +++++++++++--- man/git-summary.html | 25 ++++++++++--- man/git-summary.md | 20 ++++++++-- 5 files changed, 121 insertions(+), 51 deletions(-) diff --git a/Commands.md b/Commands.md index 287bf10..6fa0125 100644 --- a/Commands.md +++ b/Commands.md @@ -221,11 +221,16 @@ project : git-extras The `--line` option can also take a path, which will print a filtered summary for that folder or file. -The option `--oneline` tries to put as much summary information of the repo into a single output line +The option `--output-style` tries to put as much summary information of the repo into defined styled way as possible. +This is how the `tebular` output style and `oneline` output style look like ```bash -$ git summary --oneline -git-extras / age: 5 days / last active: 5 days ago / active on 799 days / commits: 1692 / uncommitted: 4 +$ git summary --output-style tabular +# Repo | Age | Last active | Active on | Commits | Uncommitted +git-extras | 13 years | 7 hours ago | 807 days | 1703 | 3 + +$ git summary --output-style oneline +git-extras / age: 13 years / last active: 7 hours ago / active on 807 days / commits: 1703 / uncommitted: 3 ``` ## git effort diff --git a/bin/git-summary b/bin/git-summary index 27cc2f5..ef2dcf0 100755 --- a/bin/git-summary +++ b/bin/git-summary @@ -6,7 +6,7 @@ cd "$(git root)" || { echo "Can't cd to top level directory";exit 1; } SUMMARY_BY_LINE= DEDUP_BY_EMAIL= MERGES_ARG= -SUMMARY_ONELINE= +OUTPUT_STYLE= for arg in "$@"; do case "$arg" in --line) @@ -18,8 +18,9 @@ for arg in "$@"; do --no-merges) MERGES_ARG="--no-merges" ;; - --oneline) - SUMMARY_ONELINE=1 + --output-style) + OUTPUT_STYLE="$2" + shift ;; -*) >&2 echo "unknown argument $arg found" @@ -189,39 +190,60 @@ uncommitted_changes_count() { git status --porcelain | wc -l } -# summary -if [ -n "$SUMMARY_BY_LINE" ] && [ -n "$SUMMARY_ONELINE" ]; then - echo "$project / lines: $(line_count "${paths[@]}")" -elif [ -n "$SUMMARY_BY_LINE" ]; then - echo - echo " project : $project" - echo " lines : $(line_count "${paths[@]}")" - echo " authors :" - lines "${paths[@]}" | sort | uniq -c | sort -rn | format_authors -elif [ -n "$SUMMARY_ONELINE" ]; then - echo "$project / age: $(repository_age) / last active: $(last_active) / active on $(active_days "$commit") days / commits: $(commit_count "$commit") / uncommitted: $(uncommitted_changes_count)" -else - echo - echo " project : $project" - echo " repo age : $(repository_age)" - echo " last active : $(last_active)" - # shellcheck disable=SC2086 - echo " active on : $(active_days $commit) days" - # shellcheck disable=SC2086 - echo " commits : $(commit_count $commit)" - # The file count doesn't support passing a git ref so ignore it if a ref is given - if [ "$commit" == "HEAD" ]; then - echo " files : $(file_count)" +COLUMN_CMD_DELIMTER="¬" # Hopefully, this symbol is not used in branch names... I use it as a seperator for columns +SP="$COLUMN_CMD_DELIMTER|" + +print_summary_by_line() { + if [ "$OUTPUT_STYLE" == "tabular" ]; then + tabular_headers="# Repo $SP Lines" + echo -e "$tabular_headers\n$project $SP $(line_count "${paths[@]}")" | column -t -s "$COLUMN_CMD_DELIMTER" + elif [ "$OUTPUT_STYLE" == "oneline" ]; then + echo "$project / lines: $(line_count "${paths[@]}")" + elif [ -n "$SUMMARY_BY_LINE" ]; then + echo + echo " project : $project" + echo " lines : $(line_count "${paths[@]}")" + echo " authors :" + lines "${paths[@]}" | sort | uniq -c | sort -rn | format_authors fi - echo " uncommitted : $(uncommitted_changes_count)" - echo " authors : " - if [ -n "$DEDUP_BY_EMAIL" ]; then - # the $commit can be empty - # shellcheck disable=SC2086 - git shortlog $MERGES_ARG -n -s -e $commit | dedup_by_email | format_authors +} + +print_summary() { + if [ "$OUTPUT_STYLE" == "tabular" ]; then + tabular_headers="# Repo $SP Age $SP Last active $SP Active on $SP Commits $SP Uncommitted" + echo -e "$tabular_headers\n$project $SP $(repository_age) $SP $(last_active) $SP $(active_days $commit) days $SP $(commit_count $commit) $SP $(uncommitted_changes_count)" | column -t -s "$COLUMN_CMD_DELIMTER" + elif [ "$OUTPUT_STYLE" == "oneline" ]; then + echo "$project / age: $(repository_age) / last active: $(last_active) / active on $(active_days $commit) days / commits: $(commit_count $commit) / uncommitted: $(uncommitted_changes_count)" else + echo + echo " project : $project" + echo " repo age : $(repository_age)" + echo " last active : $(last_active)" # shellcheck disable=SC2086 - git shortlog $MERGES_ARG -n -s $commit | format_authors + echo " active on : $(active_days $commit) days" + # shellcheck disable=SC2086 + echo " commits : $(commit_count $commit)" + + # The file count doesn't support passing a git ref so ignore it if a ref is given + if [ "$commit" == "HEAD" ]; then + echo " files : $(file_count)" + fi + echo " uncommitted : $(uncommitted_changes_count)" + echo " authors : " + if [ -n "$DEDUP_BY_EMAIL" ]; then + # the $commit can be empty + # shellcheck disable=SC2086 + git shortlog $MERGES_ARG -n -s -e $commit | dedup_by_email | format_authors + else + # shellcheck disable=SC2086 + git shortlog $MERGES_ARG -n -s $commit | format_authors + fi fi +} + +if [ -n "$SUMMARY_BY_LINE" ]; then + print_summary_by_line +else + print_summary fi diff --git a/man/git-summary.1 b/man/git-summary.1 index 8dc8049..f0eae75 100644 --- a/man/git-summary.1 +++ b/man/git-summary.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-SUMMARY" "1" "January 2023" "" "Git Extras" +.TH "GIT\-SUMMARY" "1" "February 2023" "" "Git Extras" . .SH "NAME" \fBgit\-summary\fR \- Show repository summary @@ -66,10 +66,13 @@ Summarize with lines other than commits\. When \fB\-\-line\fR is specified, the This option can not be used together with \fB\-\-dedup\-by\-email\fR or \fB\-\-no\-merges\fR\. . .P -\-\-oneline +\-\-output\-style