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

Improved the 'git-info' command (color, submodule, config) #867

Merged
merged 11 commits into from Aug 25, 2020
9 changes: 7 additions & 2 deletions Commands.md
Expand Up @@ -750,15 +750,20 @@ $ git info
myBranch
* master

## Submodule(s):

a234567 path2submodule1/submodule1 (branch/tag)
+ b234567 path2submodule2/submodule2 (branch/tag)
- c234567 path2submodule3/submodule3 (branch/tag)
e234567 path2submodule4/submodule4 (branch/tag)

## Most Recent Commit:

commit e3952df2c172c6f3eb533d8d0b1a6c77250769a7
Author: Sample Author <sampleAuthor@gmail.com>

Added git-info command.

Type 'git log' for more commits, or 'git show <commit id>' for full commit details.

## Configuration (.git/config):

color.diff=auto
Expand Down
58 changes: 45 additions & 13 deletions bin/git-info
@@ -1,11 +1,40 @@
#!/usr/bin/env bash

GREEN="$(tput setaf 2)"
NORMAL="$(tput sgr0)"
if [ "$1" = "--color" ] || [ "$2" = "--color" ] || \
[ "$1" = "-c" ] || [ "$2" = "-c" ] ; then
COLOR_TITLE="$GREEN"
else
COLOR_TITLE="$NORMAL"
fi

HIDE_CONFIG=
if [ "$1" != "--no-config" ] && [ "$2" != "--no-config" ]; then
HIDE_CONFIG=1
fi

get_config() {
git config --list
cmd_get_config="$(git config --get-all git-extras.info.config-grep)"
if [ -z "$cmd_get_config" ]; then
git config --list
else
eval "$cmd_get_config"
fi
}

most_recent_commit() {
git log --max-count=1 --pretty=short
cmd_get_log="$(git config --get-all git-extras.info.log)"
if [ -z "$cmd_get_log" ]; then
git log --max-count=1 --pretty=short
else
eval "$cmd_get_log"
fi
}

submodules() {
# short sha1
git submodule status | sed 's/\([^abcdef0-9]\{,2\}\)\([abcdef0-9]\{7\}\)\([abcdef0-9]\{33\}\)\(.*\)/\1\2\4/'
}

local_branches() {
Expand All @@ -21,27 +50,30 @@ remote_urls() {
}

echon() {
echo "$@"
echo
echo "$@"
echo
}

# Show info similar to svn

echo
echon "## Remote URLs:"
echon "${COLOR_TITLE}## Remote URLs:${NORMAL}"
echon "$(remote_urls)"

echon "## Remote Branches:"
echon "${COLOR_TITLE}## Remote Branches:${NORMAL}"
echon "$(remote_branches)"

echon "## Local Branches:"
echon "${COLOR_TITLE}## Local Branches:${NORMAL}"
echon "$(local_branches)"

echon "## Most Recent Commit:"
SUBMODULES_LOG=$(submodules)
if [ ! -z "$SUBMODULES_LOG" ]; then
echon "${COLOR_TITLE}## Submodule(s):${NORMAL}"
echon "$SUBMODULES_LOG"
fi

echon "${COLOR_TITLE}## Most Recent Commit:${NORMAL}"
echon "$(most_recent_commit)"
echon "Type 'git log' for more commits, or 'git show <commit id>' for full commit details."

if test "$1" != "--no-config"; then
echon "## Configuration (.git/config):"
if [ ! -z "$HIDE_CONFIG" ]; then
echon "${COLOR_TITLE}## Configuration (.git/config):${NORMAL}"
echon "$(get_config)"
fi
4 changes: 4 additions & 0 deletions etc/bash_completion.sh
Expand Up @@ -143,6 +143,10 @@ _git_undo(){
__gitcomp "--hard --soft -h -s"
}

_git_info(){
__gitcomp "--color -c --no-config"
}

_git_browse(){
__git_complete_remote_or_refspec
}
87 changes: 81 additions & 6 deletions man/git-info.1
@@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-INFO" "1" "October 2017" "" "Git Extras"
.TH "GIT\-INFO" "1" "August 2020" "" "Git Extras"
.
.SH "NAME"
\fBgit\-info\fR \- Returns information on current repository
.
.SH "SYNOPSIS"
\fBgit\-info\fR
\fBgit\-info\fR [\-c|\-\-color] [\-\-no\-config]
.
.SH "DESCRIPTION"
Shows the following information about a repository:
Expand All @@ -22,15 +22,85 @@ Remote Branches
Local Branches
.
.IP "4." 4
Most recent commit
Submodule(s) (if present)
.
.IP "5." 4
Most recent commit
.
.IP "6." 4
Configuration Info
.
.IP "" 0
.
.SH "OPTIONS"
N/A
\-c, \-\-color
.
.P
Use color for information titles\.
.
.P
\-\-no\-config
.
.P
Don\'t show list all variables set in config file, along with their values\.
.
.SH "GIT CONFIGS"
You could customize the Most recent commit and Configuration Info format via git config options
.
.IP "" 4
.
.nf

$ git config \-\-global \-\-add git\-extras\.info\.log "<log\-command>"
.
.fi
.
.IP "" 0
.
.P
the default \fIlog\-command\fR is "git log \-\-max\-count=1 \-\-pretty=short"
.
.IP "" 4
.
.nf

$ git config \-\-global \-\-add git\-extras\.info\.config\-grep "<config\-grep\-command>"
.
.fi
.
.IP "" 0
.
.P
the default \fIconfig\-grep\-command\fR is "git config \-\-list"
.
.P
For example,
.
.P
to set global configuration to show last commit subject, without sha1
.
.IP "" 4
.
.nf

$ git config \-\-global \-\-add git\-extras\.info\.log "git log \-\-max\-count=1 \-\-format=\e"Author: %an%nDate: %ad (%ar)%n%n %s\e" \-\-date=format:\e"%Y\-%m\-%d %a %H:%M\e""
.
.fi
.
.IP "" 0
.
.P
to set global configuration to show user\'s name and email
.
.IP "" 4
.
.nf

$ git config \-\-global \-\-add git\-extras\.info\.config\-grep "git config \-\-list | grep \-\-color=never \-E \e"^user\.name|^user\.email\e""
.
.fi
.
.IP "" 0
.
.SH "EXAMPLES"
Outputs info about a repo:
Expand All @@ -56,15 +126,20 @@ origin/myBranch
myBranch
* master

## Submodule(s):

a234567 path2submodule1/submodule1 (branch/tag)
+ b234567 path2submodule2/submodule2 (branch/tag)
\- c234567 path2submodule3/submodule3 (branch/tag)
e234567 path2submodule4/submodule4 (branch/tag)

## Most Recent Commit:

commit e3952df2c172c6f3eb533d8d0b1a6c77250769a7
Author: Sample Author <sampleAuthor@gmail\.com>

Added git\-info command\.

Type \'git log\' for more commits, or \'git show <commit id>\' for full commit details\.

## Configuration (\.git/config):

color\.diff=auto
Expand Down
51 changes: 45 additions & 6 deletions man/git-info.html

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