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..f06054cdf --- /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