From 052275b71b2580e040fd4b1f97dfe7fd3d58ec0b Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Tue, 6 Jan 2015 10:25:15 +0000 Subject: [PATCH] Set author/committer name/email from dotfiles. Read author name from .git_author_name and author email from .git_author_email. Read committer name and email from .git_commiter_name and .git_committer_email. Fall back to author name/email if committer name/email is undefined. Look in HOME first then PROFILE_HOME, unlike many other profile scripts which override settings in HOME with PROFILE_HOME. --- .profile.d/git-commit-tree.bashrc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .profile.d/git-commit-tree.bashrc diff --git a/.profile.d/git-commit-tree.bashrc b/.profile.d/git-commit-tree.bashrc new file mode 100644 index 0000000..37ec8eb --- /dev/null +++ b/.profile.d/git-commit-tree.bashrc @@ -0,0 +1,39 @@ +# Set GIT_AUTHOR_NAME etc from dotfiles in the profile. +function git_commit_tree() { + local WHO=$1; shift + local who=${WHO,,} + local WHAT= + + for WHAT in EMAIL NAME; do + local what=${WHAT,,} + local where= + + # Look in $HOME then $PROFILE_HOME. + for where in '~' '$PROFILE_HOME'; do + eval local value=\$\(\<${where}/".git_${who}_${what}"\) 2>/dev/null + + if [ -z "$value" ]; then + # COMMITTER defaults to AUTHOR. + if [ "$WHO" = "COMMITTER" ]; then + eval value="\$GIT_AUTHOR_${WHAT}" + fi + + # Fall back to generic file. + if [ -z "$value" ]; then + eval value=\$\(\<\$${where}/".git_${what}"\) 2>/dev/null + fi + fi + + if [ -n "$value" ]; then + eval export "GIT_${WHO}_${WHAT}=\$value" + # Skip next location. + break + fi + done + done +} + +git_commit_tree AUTHOR +git_commit_tree COMMITTER + +unset git_commit_tree -- 2.7.4