From 99ea5767d8fdfb577c9563eb5c932cde90c45ccb Mon Sep 17 00:00:00 2001 From: Joe Block Date: Sat, 30 Jun 2018 07:44:43 -0600 Subject: [PATCH 1/2] Add git-whoami --- README.md | 1 + bin/git-whoami | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 bin/git-whoami diff --git a/README.md b/README.md index 62acbf8b3..25f7d59af 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ If you aren't using any ZSH frameworks, or if you're a `bash` user, do the follo | `git-what-the-hell-just-happened` | Gary Bernhardt's [dotfiles](https://github.com/garybernhardt/dotfiles/blob/master/bin/git-what-the-hell-just-happened) | Show what just happened. | | `git-when-merged` | Michael Haggerty [git-when-merged](https://github.com/mhagger/git-when-merged) | Find when a commit was merged into one or more branches. | | `git-where` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | Shows where a particular commit falls between releases. | +| `git-whoami` | Peter Eisentraut | Shows what username & email you have configured for the repo you're in | | `git-winner` | Garry Dolley [https://github.com/up_the_irons/git-winner](https://github.com/up_the_irons/git-winner) | Shows what authors have made the most commits, both by number of commits and by number of lines changed. | | `git-wtf` | William Morgan | `git-wtf` displays the state of your repository in a readable, easy-to-scan format. It's useful for getting a summary of how a branch relates to a remote server, and for wrangling many topic branches. | | `github-open` | Ryan Tomayko's [dotfiles](http://github.com/rtomayko/dotfiles) | | diff --git a/bin/git-whoami b/bin/git-whoami new file mode 100755 index 000000000..b54b3f754 --- /dev/null +++ b/bin/git-whoami @@ -0,0 +1,33 @@ +#!/bin/sh + +# git-whoami +# Author: Peter Eisentraut +# Created: 2011-10-27 +# License: WTFPL; see http://sam.zoy.org/wtfpl/ + +# exact logic in ident.c in git source tree + +set -e + +get_email() { + git config user.email || ( [ -n "$EMAIL" ] && echo "$EMAIL" ) || echo "$(id -nu)@$(hostname --fqdn)" +} + +get_name() { + git config user.name || getent passwd $(id -un) | cut -d : -f 5 | cut -d , -f 1 +} + +: ${GIT_AUTHOR_NAME=$(get_name)} +: ${GIT_COMMITTER_NAME=$(get_name)} +: ${GIT_AUTHOR_EMAIL=$(get_email)} +: ${GIT_COMMITTER_EMAIL=$(get_email)} + +author="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" +commit="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" + +if [ "$author" = "$commit" ]; then + echo "$author" +else + echo "Author: $author" + echo "Commit: $commit" +fi \ No newline at end of file From 6dde88da581c9a70399379550381e54d007bf653 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Sun, 1 Jul 2018 07:22:00 -0600 Subject: [PATCH 2/2] shellcheck fixes in git-whoami --- bin/git-whoami | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/git-whoami b/bin/git-whoami index b54b3f754..f06054cdf 100755 --- a/bin/git-whoami +++ b/bin/git-whoami @@ -14,13 +14,13 @@ get_email() { } get_name() { - git config user.name || getent passwd $(id -un) | cut -d : -f 5 | cut -d , -f 1 + git config user.name || getent passwd "$(id -un)" | cut -d : -f 5 | cut -d , -f 1 } -: ${GIT_AUTHOR_NAME=$(get_name)} -: ${GIT_COMMITTER_NAME=$(get_name)} -: ${GIT_AUTHOR_EMAIL=$(get_email)} -: ${GIT_COMMITTER_EMAIL=$(get_email)} +: ${GIT_AUTHOR_NAME="$(get_name)"} +: ${GIT_COMMITTER_NAME="$(get_name)"} +: ${GIT_AUTHOR_EMAIL="$(get_email)"} +: ${GIT_COMMITTER_EMAIL="$(get_email)"} author="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" commit="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" @@ -30,4 +30,4 @@ if [ "$author" = "$commit" ]; then else echo "Author: $author" echo "Commit: $commit" -fi \ No newline at end of file +fi