37ec8ebeddbc8eb3267efe813d678ba3a0da1578
[profile.git] / .profile.d / git-commit-tree.bashrc
1 # Set GIT_AUTHOR_NAME etc from dotfiles in the profile.
2 function git_commit_tree() {
3   local WHO=$1; shift
4   local who=${WHO,,}
5   local WHAT=
6
7   for WHAT in EMAIL NAME; do
8     local what=${WHAT,,}
9     local where=
10
11     # Look in $HOME then $PROFILE_HOME.
12     for where in '~' '$PROFILE_HOME'; do
13       eval local value=\$\(\<${where}/".git_${who}_${what}"\) 2>/dev/null
14
15       if [ -z "$value" ]; then
16         # COMMITTER defaults to AUTHOR.
17         if [ "$WHO" = "COMMITTER" ]; then
18           eval value="\$GIT_AUTHOR_${WHAT}"
19         fi
20
21         # Fall back to generic file.
22         if [ -z "$value" ]; then
23             eval value=\$\(\<\$${where}/".git_${what}"\) 2>/dev/null
24         fi
25       fi
26
27       if [ -n "$value" ]; then
28         eval export "GIT_${WHO}_${WHAT}=\$value"
29         # Skip next location.
30         break
31       fi
32     done
33   done
34 }
35
36 git_commit_tree AUTHOR
37 git_commit_tree COMMITTER
38
39 unset git_commit_tree