Skip to content

Commit

Permalink
Add git-whoami
Browse files Browse the repository at this point in the history
  • Loading branch information
unixorn committed Jun 30, 2018
1 parent 4b5437a commit 99ea576
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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 <wmorgan-git-wt-add@masanjin.net> | `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) | |
Expand Down
33 changes: 33 additions & 0 deletions bin/git-whoami
@@ -0,0 +1,33 @@
#!/bin/sh

# git-whoami
# Author: Peter Eisentraut <peter@eisentraut.org>
# 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

0 comments on commit 99ea576

Please sign in to comment.