From 7c441e51995a209d727c5fb989c43e049e3f8175 Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Sun, 2 Jun 2019 01:58:57 -0400 Subject: [PATCH 1/7] Add: colored output to git-info --- bin/git-info | 52 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/bin/git-info b/bin/git-info index 2fdee7101..647ee6b18 100755 --- a/bin/git-info +++ b/bin/git-info @@ -1,47 +1,31 @@ #!/usr/bin/env bash -get_config() { - git config --list +header() { + tput setaf 242 + printf "## $1\n\n" + tput sgr0 } -most_recent_commit() { - git log --max-count=1 --pretty=short -} - -local_branches() { - git branch -} - -remote_branches() { - git branch -r -} - -remote_urls() { - git remote -v -} - -echon() { - echo "$@" - echo +run() { + eval "$1" + printf "\n\n" } # Show info similar to svn -echo -echon "## Remote URLs:" -echon "$(remote_urls)" +header "Remote URLs:" +run "git remote -v" -echon "## Remote Branches:" -echon "$(remote_branches)" +header "Remote Branches:" +run "git branch -r --color=always" -echon "## Local Branches:" -echon "$(local_branches)" +header "Local Branches:" +run "git branch --color=always" -echon "## Most Recent Commit:" -echon "$(most_recent_commit)" -echon "Type 'git log' for more commits, or 'git show ' for full commit details." +header "Most Recent Commit:" +run "git --no-pager log --max-count=1 --pretty=short --color=always" -if test "$1" != "--no-config"; then - echon "## Configuration (.git/config):" - echon "$(get_config)" +if [[ "$1" != "--no-config" ]] && [[ "$1" != "-n" ]]; then + header "Configuration (.git/config):" + git --no-pager config --list fi From 3b60b411d342ad150180baf6a997416f71229a84 Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Sun, 2 Jun 2019 02:08:35 -0400 Subject: [PATCH 2/7] Doc: include git-info '-n' option in Commands.md --- Commands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands.md b/Commands.md index a4cb6b929..64365cea1 100644 --- a/Commands.md +++ b/Commands.md @@ -731,7 +731,7 @@ $ git info ``` -If you wish to omit the config section, you may use `--no-config`: +If you wish to omit the config section, you may use `--no-config` (or `-n`): ```bash $ git info --no-config From b75b28562086faa245d6e92b099f19e05a2335dc Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Sun, 2 Jun 2019 02:19:31 -0400 Subject: [PATCH 3/7] Mod: better use of whitespace in output --- bin/git-info | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/git-info b/bin/git-info index 647ee6b18..cd7aae2f0 100755 --- a/bin/git-info +++ b/bin/git-info @@ -2,13 +2,13 @@ header() { tput setaf 242 - printf "## $1\n\n" + printf "### $1\n" tput sgr0 } run() { eval "$1" - printf "\n\n" + printf "\n" } # Show info similar to svn From 9df13b9bdea6e1f2bf9c3157e06eaea6c2a5e28b Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Sun, 2 Jun 2019 03:39:52 -0400 Subject: [PATCH 4/7] Mod: clear screen before running commands in 'git-info' --- bin/git-info | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/git-info b/bin/git-info index cd7aae2f0..09dfb02b0 100755 --- a/bin/git-info +++ b/bin/git-info @@ -1,5 +1,7 @@ #!/usr/bin/env bash +clear + header() { tput setaf 242 printf "### $1\n" From 0ca9146d03a718566c7f22094dac4fb6b4675e39 Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Sun, 2 Jun 2019 04:07:22 -0400 Subject: [PATCH 5/7] Add: --no-color option --- Commands.md | 6 ++++++ bin/git-info | 33 ++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Commands.md b/Commands.md index 64365cea1..e463ffc92 100644 --- a/Commands.md +++ b/Commands.md @@ -737,6 +737,12 @@ If you wish to omit the config section, you may use `--no-config` (or `-n`): $ git info --no-config ``` +By default, the output is colored to make it easier on the eyes. When this is not desired (if piping the output of `git info` to another command, for example), the `--no-color` option may be used: + +```bash +$ git info --no-color +``` + ## git create-branch Create local branch `name`: diff --git a/bin/git-info b/bin/git-info index 09dfb02b0..5309d0694 100755 --- a/bin/git-info +++ b/bin/git-info @@ -2,30 +2,49 @@ clear + +color="--color=always" +no_color="--no-color" +if [[ "$1" == "${no_color}" ]]; then + color="$1"; shift +else + if [[ "$2" == "${no_color}" ]]; then + color="$2" + fi +fi + + header() { - tput setaf 242 + if [[ "${color}" != "${no_color}" ]]; then + tput setaf 242 + fi + printf "### $1\n" - tput sgr0 + + if [[ "${color}" != "${no_color}" ]]; then + tput sgr0 + fi } -run() { +git_cmd() { eval "$1" printf "\n" } + # Show info similar to svn header "Remote URLs:" -run "git remote -v" +git_cmd "git remote -v" header "Remote Branches:" -run "git branch -r --color=always" +git_cmd "git branch -r ${color}" header "Local Branches:" -run "git branch --color=always" +git_cmd "git branch ${color}" header "Most Recent Commit:" -run "git --no-pager log --max-count=1 --pretty=short --color=always" +git_cmd "git --no-pager log --max-count=1 --pretty=short ${color}" if [[ "$1" != "--no-config" ]] && [[ "$1" != "-n" ]]; then header "Configuration (.git/config):" From 1d3de77fda2fddf1b1ba09ae5ca1c714dec2b307 Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Sun, 2 Jun 2019 04:08:07 -0400 Subject: [PATCH 6/7] Mod: removed the -n option Now that --no-config and --no-color are now both valid options, the shorter -n option is no longer obvious. --- Commands.md | 2 +- bin/git-info | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Commands.md b/Commands.md index e463ffc92..5cd9075e7 100644 --- a/Commands.md +++ b/Commands.md @@ -731,7 +731,7 @@ $ git info ``` -If you wish to omit the config section, you may use `--no-config` (or `-n`): +If you wish to omit the config section, you may use `--no-config`: ```bash $ git info --no-config diff --git a/bin/git-info b/bin/git-info index 5309d0694..81f1620d6 100755 --- a/bin/git-info +++ b/bin/git-info @@ -46,7 +46,7 @@ git_cmd "git branch ${color}" header "Most Recent Commit:" git_cmd "git --no-pager log --max-count=1 --pretty=short ${color}" -if [[ "$1" != "--no-config" ]] && [[ "$1" != "-n" ]]; then +if [[ "$1" != "--no-config" ]]; then header "Configuration (.git/config):" git --no-pager config --list fi From bf7dd6974170e603fe3421d06166e3f732353db2 Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Sun, 2 Jun 2019 04:50:39 -0400 Subject: [PATCH 7/7] Add: the '-c ' option (where '' is an integer) This option specifies the number of commits to show in the output (``). --- Commands.md | 14 ++++++++++++++ bin/git-info | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Commands.md b/Commands.md index 5cd9075e7..a7f2ff582 100644 --- a/Commands.md +++ b/Commands.md @@ -743,6 +743,20 @@ By default, the output is colored to make it easier on the eyes. When this is no $ git info --no-color ``` +You can select the number of previous commits to show by using the `-c ` option (where `` is any integer). It is important to note, however, that `-c` **must be the FIRST option** you pass to `git info`. For example: + +```bash +$ git info -c 5 --no-config +``` + +will display the 5 most recent commits as apart of its output (and omit the configuration section), but + +```bash +$ git info --no-config -c 5 +``` + +will NOT recognize that the `-c` option was used. Consequently, the output will contain only the single most recent commit (the default action). + ## git create-branch Create local branch `name`: diff --git a/bin/git-info b/bin/git-info index 81f1620d6..8841c3f83 100755 --- a/bin/git-info +++ b/bin/git-info @@ -3,6 +3,12 @@ clear +max_count=1 +if [[ "$1" == "-c" ]]; then + shift + max_count="$1"; shift +fi + color="--color=always" no_color="--no-color" if [[ "$1" == "${no_color}" ]]; then @@ -43,8 +49,14 @@ git_cmd "git branch -r ${color}" header "Local Branches:" git_cmd "git branch ${color}" -header "Most Recent Commit:" -git_cmd "git --no-pager log --max-count=1 --pretty=short ${color}" +if [[ "${max_count}" -ne 1 ]]; then + header="Top ${max_count} Commits:" +else + header="Most Recent Commit:" +fi + +header "${header}" +git_cmd "git --no-pager log --max-count=${max_count} --pretty=short ${color}" if [[ "$1" != "--no-config" ]]; then header "Configuration (.git/config):"