Last active
May 17, 2017 15:15
-
-
Save kevsmith/4f7cf261f28c2d9ebbf021d25bda8e22 to your computer and use it in GitHub Desktop.
View age information about local, remote, and merged-to-master git branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Valid branch types: remote, local, merged | |
local_branch_opt="-a" | |
remote_branch_opt="-r" | |
merged_branch_opt="-a --merged master" | |
print_help() { | |
echo "git branches [<branch_type>] [-r|--reverse]" | |
echo "" | |
echo "Valid branch types: remote (default), local, merged" | |
} | |
display_branch_info() { | |
branch_opt="" | |
caption="remote" | |
case $1 in | |
"local") | |
branch_opt=${local_branch_opt} | |
caption="local" | |
;; | |
"merged") | |
branch_opt=${merged_branch_opt} | |
caption="merged to master" | |
;; | |
*) | |
branch_opt=${remote_branch_opt} | |
;; | |
esac | |
for k in `git branch ${branch_opt} | awk '{print \$1}'` | |
do | |
echo `git show --pretty=format:"%Cgreen%ci %Cblue%cr %Cred%cn %Creset" $k | head -n 1` $k \(${caption}\) | |
done | sort ${2} | |
} | |
branch_type="remote" | |
sort_opt="-r" | |
while [ $# -gt 0 ] | |
do | |
case ${1} in | |
"local") | |
branch_type=${1} | |
;; | |
"merged") | |
branch_type=${1} | |
;; | |
"remote") | |
branch_type=${1} | |
;; | |
"-r") | |
sort_opt="" | |
;; | |
"--reverse") | |
sort_opt="" | |
;; | |
"help") | |
print_help | |
exit 0 | |
;; | |
*) | |
print_help | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
case ${branch_type} in | |
"remote") | |
;; | |
"local") | |
;; | |
"merged") | |
;; | |
*) | |
print_help | |
exit 1 | |
;; | |
esac | |
case ${2} in | |
"-r") | |
sort_opt="" | |
;; | |
"--reverse") | |
sort_opt="" | |
;; | |
"") | |
true | |
;; | |
*) | |
print_help | |
exit 1 | |
;; | |
esac | |
display_branch_info ${branch_type} ${sort_opt} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HOT DIGGITY!