Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reverse option to git-brv #1123

Merged
merged 5 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ $ git brv
2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec
```

When your repo has many branches, it can be more convenient to see this list in reverse. This can be set as the default by setting the GIT_BRV_REVERSE environment variable to true.

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

## git repl

Expand Down
21 changes: 20 additions & 1 deletion bin/git-brv
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ if ! (( BASH_VERSINFO[0] > 4 ||
exit 1
fi

# allow the user to set a default reverse option in an environment variable
reverse=${GIT_BRV_REVERSE:-false}
joshka marked this conversation as resolved.
Show resolved Hide resolved
while [[ $# -gt 0 ]]; do
case $1 in
-r | --reverse)
reverse=true
shift
;;
*)
break
;;
esac
done

if [[ -t 1 ]]; then
shopt -s checkwinsize
COLUMNS=$(tput cols)
Expand Down Expand Up @@ -36,9 +50,14 @@ for b in "${!upstream[@]}"; do
done

mapfile -t ordered < <(
# the reverse option of git-brv causes the sort to be sorted normally rather than in reverse
reverse_opt=""
if [[ $reverse = false ]]; then
reverse_opt="-r"
fi
for b in "${!date[@]}"; do
printf '%d\t%s\n' "${date[$b]}" "$b"
done | sort -rn | cut -f2-
done | sort -n $reverse_opt | cut -f2-
)

current=$(git symbolic-ref -q --short HEAD)
Expand Down
4 changes: 4 additions & 0 deletions etc/bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ _git_authors(){
__gitcomp "-l --list --no-email"
}

_git_brv(){
__gitcomp "-r --reverse"
}

_git_coauthor(){
local oldIfs=$IFS
IFS=$'\n'
Expand Down
5 changes: 5 additions & 0 deletions etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ _git-authors() {
'--no-email[without email]' \
}

_git-brv() {
_arguments \
'(-r --reverse)'{-r,--reverse}'[reverse order]'
}

_git-changelog() {
_arguments \
'(-l --list)'{-l,--list}'[list commits]' \
Expand Down
2 changes: 2 additions & 0 deletions etc/git-extras.fish
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ complete -c git -n __fish_git_needs_command -a "$__fish_git_extras_commands"
# authors
complete -c git -f -n '__fish_git_using_command authors' -s l -l list -d 'show authors'
complete -c git -f -n '__fish_git_using_command authors' -l no-email -d 'without email'
# brv
complete -c git -f -n '__fish_git_using_command brv' -s r -l reverse -d 'reverse the sort order'
# bulk
complete -c git -n '__fish_git_using_command bulk' -s a -d 'Run a git command on all workspaces and their repositories'
complete -c git -n '__fish_git_using_command bulk' -s g -d 'Ask the user for confirmation on every execution'
Expand Down
25 changes: 23 additions & 2 deletions man/git-brv.1
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-BRV" "1" "January 2020" "" "Git Extras"
.TH "GIT\-BRV" "1" "December 2023" "" "Git Extras"
.
.SH "NAME"
\fBgit\-brv\fR \- List branches sorted by their last commit date
.
.SH "SYNOPSIS"
\fBgit\-brv\fR
\fBgit\-brv\fR [\-r|\-\-reverse]
.
.SH "DESCRIPTION"
Pretty listing of branches sorted by the date of their last commit\.
.
.SH "OPTIONS"
\-r | \-\-reverse
.
.P
Reverses the output to put the most recent branch at the bottom of the list\. This is useful when there are large amount of branches as the most recent branch is shown just above the next prompt\. This can be configured as the default by setting the GIT_BRV_REVERSE environment variable to true\.
.
.SH "EXAMPLES"
Simply run \fBgit brv\fR
.
Expand All @@ -27,6 +33,21 @@ $ git brv
.
.IP "" 0
.
.P
\fBgit brv \-\-reverse\fR
.
.IP "" 4
.
.nf

$ git brv
2020\-01\-08 master origin/master 265b03e Merge pull request #816 from spacewander/git\-sed\-pathspec
2020\-01\-14 adds\-git\-brv fork/adds\-git\-brv 1ca0d76 Fixes #700: Adds git\-brv
.
.fi
.
.IP "" 0
.
.SH "AUTHOR"
Written by Øsse <\fIhttps://github\.com/Osse\fR>
.
Expand Down
18 changes: 16 additions & 2 deletions man/git-brv.html

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

13 changes: 12 additions & 1 deletion man/git-brv.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ git-brv(1) -- List branches sorted by their last commit date

## SYNOPSIS

`git-brv`
`git-brv` [-r|--reverse]

## DESCRIPTION

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

## OPTIONS

-r | --reverse

Reverses the output to put the most recent branch at the bottom of the list. This is useful when there are large amount of branches as the most recent branch is shown just above the next prompt. This can be configured as the default by setting the GIT_BRV_REVERSE environment variable to true.

## EXAMPLES

Simply run `git brv`
Expand All @@ -17,6 +23,11 @@ git-brv(1) -- List branches sorted by their last commit date
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 brv --reverse`

$ git brv
joshka marked this conversation as resolved.
Show resolved Hide resolved
2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec
2020-01-14 adds-git-brv fork/adds-git-brv 1ca0d76 Fixes #700: Adds git-brv

## AUTHOR

Expand Down
2 changes: 1 addition & 1 deletion man/git-extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ git-extras(1) -- Awesome GIT utilities
- **git-delete-tag(1)** Delete tags
- **git-delta(1)** Lists changed files
- **git-effort(1)** Show effort statistics on file(s)
- **git-feature(1)** Create/Merge feature branch
- **# git-feature(1)** Create/Merge feature branch
joshka marked this conversation as resolved.
Show resolved Hide resolved
- **git-force-clone(1)** overwrite local repositories with clone
- **git-fork(1)** Fork a repo on github
- **git-fresh-branch(1)** Create fresh branches
Expand Down