Skip to content

Commit

Permalink
Change the oneline option to a tebular version in the git summary (tj…
Browse files Browse the repository at this point in the history
…#1031)

Co-authored-by: guenthgr <[email protected]>
  • Loading branch information
2 people authored and vanpipy committed Sep 14, 2023
1 parent 6636eef commit 9636333
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 51 deletions.
11 changes: 8 additions & 3 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 55 additions & 33 deletions bin/git-summary
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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
echo " active on : $(active_days $commit) days"
# shellcheck disable=SC2086
git shortlog $MERGES_ARG -n -s $commit | format_authors
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
28 changes: 23 additions & 5 deletions man/git-summary.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 <style>
.
.P
Summarizes the repository within one line\. Some information like the authors cannot be displayed in this mode\.
Summarizes the repository and print the output accoring to the specified style\. Styles: * \fBtabular\fR: Prints the summary in a tabular form having a header in the first line and the values in the second * \fBoneline\fR: Prints the summary in a single line
.
.P
Some information like the authors cannot be displayed in this mode\.
.
.SH "EXAMPLES"
Outputs a repo summary:
Expand Down Expand Up @@ -161,14 +164,29 @@ authors :
.IP "" 0
.
.P
Tabular summary
.
.IP "" 4
.
.nf

$ git summary \-\-output\-style tabular
# Repo | Age | Last active | Active on | Commits | Uncommitted
git\-extras | 13 years | 7 hours ago | 807 days | 1703 | 3
.
.fi
.
.IP "" 0
.
.P
Oneline summary
.
.IP "" 4
.
.nf

$ 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 oneline
git\-extras / age: 13 years / last active: 7 hours ago / active on 807 days / commits: 1703 / uncommitted: 3
.
.fi
.
Expand Down
25 changes: 19 additions & 6 deletions man/git-summary.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions man/git-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ Shows a summary of the repository or a path within it.

This option can not be used together with `--dedup-by-email` or `--no-merges`.

--oneline
--output-style &lt;style&gt;

Summarizes the repository within one line. Some information like the authors cannot be displayed in this mode.
Summarizes the repository and print the output accoring to the specified style.
Styles:
* `tabular`: Prints the summary in a tabular form having a header in the
first line and the values in the second
* `oneline`: Prints the summary in a single line

Some information like the authors cannot be displayed in this mode.

## EXAMPLES

Expand Down Expand Up @@ -105,10 +111,16 @@ Shows a summary of the repository or a path within it.
authors :
...

Tabular summary

$ git summary --output-style tabular
# Repo | Age | Last active | Active on | Commits | Uncommitted
git-extras | 13 years | 7 hours ago | 807 days | 1703 | 3

Oneline summary

$ 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 oneline
git-extras / age: 13 years / last active: 7 hours ago / active on 807 days / commits: 1703 / uncommitted: 3

## AUTHOR

Expand Down

0 comments on commit 9636333

Please sign in to comment.