diff --git a/Commands.md b/Commands.md index 2aec3ac..7055544 100644 --- a/Commands.md +++ b/Commands.md @@ -750,6 +750,13 @@ $ 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 @@ -757,8 +764,6 @@ $ git info Added git-info command. - Type 'git log' for more commits, or 'git show ' for full commit details. - ## Configuration (.git/config): color.diff=auto diff --git a/bin/git-info b/bin/git-info index 2fdee71..86bb4f9 100755 --- a/bin/git-info +++ b/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() { @@ -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:" -echon "$(most_recent_commit)" -echon "Type 'git log' for more commits, or 'git show ' for full commit details." +SUBMODULES_LOG=$(submodules) +if [ ! -z "$SUBMODULES_LOG" ]; then + echon "${COLOR_TITLE}## Submodule(s):${NORMAL}" + echon "$SUBMODULES_LOG" +fi -if test "$1" != "--no-config"; then - echon "## Configuration (.git/config):" +echon "${COLOR_TITLE}## Most Recent Commit:${NORMAL}" +echon "$(most_recent_commit)" + +if [ ! -z "$HIDE_CONFIG" ]; then + echon "${COLOR_TITLE}## Configuration (.git/config):${NORMAL}" echon "$(get_config)" fi diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index 18daeb2..0c6cb00 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -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 } diff --git a/man/git-info.1 b/man/git-info.1 index 703ba53..4b4805f 100644 --- a/man/git-info.1 +++ b/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: @@ -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 "" +. +.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 "" +. +.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: @@ -56,6 +126,13 @@ 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 @@ -63,8 +140,6 @@ Author: Sample Author Added git\-info command\. -Type \'git log\' for more commits, or \'git show \' for full commit details\. - ## Configuration (\.git/config): color\.diff=auto diff --git a/man/git-info.html b/man/git-info.html index 63df727..097db48 100644 --- a/man/git-info.html +++ b/man/git-info.html @@ -57,6 +57,7 @@ SYNOPSIS DESCRIPTION OPTIONS + GIT CONFIGS EXAMPLES AUTHOR REPORTING BUGS @@ -76,7 +77,7 @@

SYNOPSIS

-

git-info

+

git-info [-c|--color] [--no-config]

DESCRIPTION

@@ -86,6 +87,7 @@
  • Remote Url(s)
  • Remote Branches
  • Local Branches
  • +
  • Submodule(s) (if present)
  • Most recent commit
  • Configuration Info
  • @@ -93,7 +95,39 @@

    OPTIONS

    -

    N/A

    +

    -c, --color

    + +

    Use color for information titles.

    + +

    --no-config

    + +

    Don't show list all variables set in config file, along with their values.

    + +

    GIT CONFIGS

    + +

    You could customize the Most recent commit and Configuration Info format via git config options

    + +
    $ git config --global --add git-extras.info.log "<log-command>"
    +
    + +

    the default log-command is "git log --max-count=1 --pretty=short"

    + +
    $ git config --global --add git-extras.info.config-grep "<config-grep-command>"
    +
    + +

    the default config-grep-command is "git config --list"

    + +

    For example,

    + +

    to set global configuration to show last commit subject, without sha1

    + +
     $ git config --global --add git-extras.info.log "git log --max-count=1 --format=\"Author: %an%nDate:   %ad (%ar)%n%n    %s\" --date=format:\"%Y-%m-%d %a %H:%M\""
    +
    + +

    to set global configuration to show user's name and email

    + +
     $ git config --global --add git-extras.info.config-grep "git config --list | grep --color=never -E \"^user.name|^user.email\""
    +

    EXAMPLES

    @@ -116,6 +150,13 @@ 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 @@ -123,8 +164,6 @@ 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 @@ -145,7 +184,7 @@ branch.master.merge=refs/heads/master

    AUTHOR

    -

    Written by Leila Muhtasib <muhtasib@gmail.com>

    +

    Written by Leila Muhtasib <muhtasib@gmail.com>

    REPORTING BUGS

    @@ -158,7 +197,7 @@ branch.master.merge=refs/heads/master
    1. -
    2. October 2017
    3. +
    4. August 2020
    5. git-info(1)
    diff --git a/man/git-info.md b/man/git-info.md index bce8cda..ed04734 100644 --- a/man/git-info.md +++ b/man/git-info.md @@ -3,7 +3,7 @@ git-info(1) -- Returns information on current repository ## SYNOPSIS -`git-info` +`git-info` [-c|--color] [--no-config] ## DESCRIPTION @@ -12,12 +12,41 @@ Shows the following information about a repository: 1. Remote Url(s) 2. Remote Branches 3. Local Branches - 4. Most recent commit - 5. Configuration Info + 4. Submodule(s) (if present) + 5. Most recent commit + 6. Configuration Info ## OPTIONS -N/A + -c, --color + + Use color for information titles. + + --no-config + + Don't show list all variables set in config file, along with their values. + +## GIT CONFIGS + + You could customize the Most recent commit and Configuration Info format via git config options + + $ git config --global --add git-extras.info.log "" + + the default is "git log --max-count=1 --pretty=short" + + $ git config --global --add git-extras.info.config-grep "" + + the default is "git config --list" + + For example, + + to set global configuration to show last commit subject, without sha1 + + $ git config --global --add git-extras.info.log "git log --max-count=1 --format=\"Author: %an%nDate: %ad (%ar)%n%n %s\" --date=format:\"%Y-%m-%d %a %H:%M\"" + + to set global configuration to show user's name and email + + $ git config --global --add git-extras.info.config-grep "git config --list | grep --color=never -E \"^user.name|^user.email\"" ## EXAMPLES @@ -40,6 +69,13 @@ Outputs info about a repo: 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 @@ -47,8 +83,6 @@ Outputs info about a repo: Added git-info command. - Type 'git log' for more commits, or 'git show ' for full commit details. - ## Configuration (.git/config): color.diff=auto