From b4d7645f2fea0417b80bb6534e38e76b6eeb6371 Mon Sep 17 00:00:00 2001 From: Anton Stroganov Date: Sat, 20 Aug 2016 14:48:59 -0700 Subject: [PATCH] git: add gbf alias to list all branches --- modules/git/README.md | 1 + modules/git/alias.zsh | 1 + modules/git/functions/git-branch-list | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 modules/git/functions/git-branch-list diff --git a/modules/git/README.md b/modules/git/README.md index c2d0449c..d4ddcc2a 100644 --- a/modules/git/README.md +++ b/modules/git/README.md @@ -42,6 +42,7 @@ Aliases - `gbs` lists branches and their commits with ancestry graphs. - `gbS` lists local and remote branches and their commits with ancestry graphs. + - `gbf` list all branches in order of last modification and who the last committer was - `gbx` deletes a branch. - `gbX` deletes a branch irrespective of its merged status. - `gbm` renames a branch. diff --git a/modules/git/alias.zsh b/modules/git/alias.zsh index ffa854dd..a59f0da9 100644 --- a/modules/git/alias.zsh +++ b/modules/git/alias.zsh @@ -40,6 +40,7 @@ alias gbm='git branch -m' alias gbM='git branch -M' alias gbs='git show-branch' alias gbS='git show-branch -a' +alias gbf='git-branch-list' # Commit (c) alias gc='git commit --verbose' diff --git a/modules/git/functions/git-branch-list b/modules/git/functions/git-branch-list new file mode 100644 index 00000000..64607b8e --- /dev/null +++ b/modules/git/functions/git-branch-list @@ -0,0 +1,19 @@ +# +# Lists the heads of branches and last modification time and user +# Stolen from someone's git alias file, unfortunately do not remember original source. +# My work was limited to reformatting this to work as a zsh alias +# +# Authors: +# Unknown +# Anton Stroganov +# + +if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then + print "$0: not a repository work tree: $PWD" >&2 + return 1 +fi + +for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/); do + git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" +done \ + | awk '! a[$0]++'