diff --git a/Commands.md b/Commands.md index b78bb19f5..f6612853f 100644 --- a/Commands.md +++ b/Commands.md @@ -5,6 +5,7 @@ - [`git back`](#git-back) - [`git bug`](#git-featurerefactorbugchore) - [`git bulk`](#git-bulk) + - [`git brv`](#git-brv) - [`git changelog`](#git-changelog) - [`git chore`](#git-featurerefactorbugchore) - [`git clear`](#git-clear) @@ -331,6 +332,17 @@ $ git bulk --removeworkspace personal $ git bulk --purge ``` +## git brv + +Pretty listing of branches sorted by the date of their last commit. + +```bash +$ git brv +2020-01-14 adds-git-brv fork/adds-git-brv 1ca0d76 Fixes #700: Adds git-brv +2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec +``` + + ## git repl Git read-eval-print-loop. Lets you run `git` commands without typing 'git'. diff --git a/bin/git-brv b/bin/git-brv new file mode 100755 index 000000000..f2d83ab31 --- /dev/null +++ b/bin/git-brv @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +# A sorted prettier branch -vv + +if ! (( BASH_VERSINFO[0] > 4 || + BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 2 )); then + printf >&2 'This script requires bash 4.2 or newer\n' + exit 1 +fi + +if [[ -t 1 ]]; then + shopt -s checkwinsize + COLUMNS=$(tput cols) + color_branch_local=$(git config --get-color color.branch.local normal) + color_branch_current=$(git config --get-color color.branch.current green) + color_diff_commit=$(git config --get-color color.diff.commit yellow) + color_branch_upstream=$(git config --get-color color.branch.upstream blue) + reset=$(tput sgr0) +fi + + +declare -A upstream date hash message +eval "$( + git for-each-ref --format='upstream[%(refname:short)]=%(upstream:short)' \ + --shell 'refs/heads/**' +)" + +for b in "${!upstream[@]}"; do + blen=${#b} ulen=${#upstream[$b]} + (( bwidth = blen > bwidth ? blen : bwidth )) + (( uwidth = ulen > uwidth ? ulen : uwidth )) + IFS=/ read -r 'date[$b]' 'hash[$b]' 'message[$b]' < <( + git log --no-walk=unsorted --format=%ct/%h/%s "$b" -- + ) + hlen=${#hash[$b]} + (( hwidth = hlen > hwidth ? hlen : hwidth )) +done + +mapfile -t ordered < <( + for b in "${!date[@]}"; do + printf '%d\t%s\n' "${date[$b]}" "$b" + done | sort -rn | cut -f2- +) + +current=$(git symbolic-ref -q --short HEAD) + +for b in "${ordered[@]}"; do + branch_color=$color_branch_local + if [[ $b = "$current" ]]; then + branch_color=$color_branch_current + fi + if [[ -t 1 ]]; then + msg=${message[$b]:0:COLUMNS-bwidth-uwidth-hwidth-14} + else + msg=${message[$b]} + fi + printf '%(%Y-%m-%d)T %s%*s%s %s%*s%s %s%*s%s %s\n' \ + "${date[$b]}" \ + "$branch_color" "-$bwidth" "$b" "$reset" \ + "$color_branch_upstream" "-$uwidth" "${upstream[$b]}" "$reset" \ + "$color_diff_commit" "-$hwidth" "${hash[$b]}" "$reset" \ + "$msg" +done \ No newline at end of file diff --git a/man/git-brv.1 b/man/git-brv.1 new file mode 100644 index 000000000..09f836bd0 --- /dev/null +++ b/man/git-brv.1 @@ -0,0 +1,37 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "GIT\-BRV" "1" "January 2020" "" "Git Extras" +. +.SH "NAME" +\fBgit\-brv\fR \- Show commit logs since some date +. +.SH "SYNOPSIS" +\fBgit\-brv\fR [] +. +.SH "DESCRIPTION" +Pretty listing of branches sorted by the date of their last commit\. +. +.SH "EXAMPLES" +Simply run \fBgit brv\fR +. +.IP "" 4 +. +.nf + +$ git brv +2020\-01\-14 adds\-git\-brv fork/adds\-git\-brv 1ca0d76 Fixes #700: Adds git\-brv +2020\-01\-08 master origin/master 265b03e Merge pull request #816 from spacewander/git\-sed\-pathspec +. +.fi +. +.IP "" 0 +. +.SH "AUTHOR" +Written by Øsse <\fIhttps://github\.com/Osse\fR> +. +.SH "REPORTING BUGS" +<\fIhttps://github\.com/tj/git\-extras/issues\fR> +. +.SH "SEE ALSO" +<\fIhttps://github\.com/tj/git\-extras\fR> diff --git a/man/git-brv.html b/man/git-brv.html new file mode 100644 index 000000000..021930bb3 --- /dev/null +++ b/man/git-brv.html @@ -0,0 +1,114 @@ + + + + + + git-brv(1) - Show commit logs since some date + + + + +
+ + + +
    +
  1. git-brv(1)
  2. +
  3. Git Extras
  4. +
  5. git-brv(1)
  6. +
+ +

NAME

+

+ git-brv - Show commit logs since some date +

+ +

SYNOPSIS

+ +

git-brv [<date>]

+ +

DESCRIPTION

+ +

Pretty listing of branches sorted by the date of their last commit.

+ +

EXAMPLES

+ +

Simply run git brv

+ +
$ git brv
+2020-01-14 adds-git-brv fork/adds-git-brv 1ca0d76 Fixes #700: Adds git-brv
+2020-01-08 master       origin/master     265b03e Merge pull request #816 from spacewander/git-sed-pathspec
+
+ +

AUTHOR

+ +

Written by Øsse <https://github.com/Osse>

+ +

REPORTING BUGS

+ +

<https://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. January 2020
  3. +
  4. git-brv(1)
  5. +
+ +
+ + diff --git a/man/git-brv.md b/man/git-brv.md new file mode 100644 index 000000000..b29aa225c --- /dev/null +++ b/man/git-brv.md @@ -0,0 +1,31 @@ +git-brv(1) -- Show commit logs since some date +======================================================== + +## SYNOPSIS + +`git-brv` [<date>] + +## DESCRIPTION + + Pretty listing of branches sorted by the date of their last commit. + +## EXAMPLES + + Simply run `git brv` + + $ git brv + 2020-01-14 adds-git-brv fork/adds-git-brv 1ca0d76 Fixes #700: Adds git-brv + 2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec + + +## AUTHOR + +Written by Øsse <> + +## REPORTING BUGS + +<> + +## SEE ALSO + +<> diff --git a/man/git-extras.md b/man/git-extras.md index 1acaffe7b..be0a126d5 100644 --- a/man/git-extras.md +++ b/man/git-extras.md @@ -25,6 +25,7 @@ git-extras(1) -- Awesome GIT utilities - **git-archive-file(1)** Export the current HEAD of the git repository to an archive - **git-authors(1)** Generate authors report - **git-back(1)** Undo and Stage latest commits + - **git-brv(1)** Show commit logs since some date - **git-bug(1)** Create bug branch - **git-bulk(1)** Run git commands on multiple repositories - **git-changelog(1)** Generate a changelog report diff --git a/man/index.txt b/man/index.txt index 8b7bac494..37175f52f 100644 --- a/man/index.txt +++ b/man/index.txt @@ -3,6 +3,7 @@ git-alias(1) git-alias git-archive-file(1) git-archive-file git-authors(1) git-authors git-back(1) git-back +git-brv(1) git-brv git-bug(1) git-bug git-bulk(1) git-bulk git-changelog(1) git-changelog