diff options
author | Andrew Cady <d@jerkface.net> | 2020-05-28 18:20:35 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-05-28 18:25:26 -0400 |
commit | 9fbd4a9ea4ce0ef8df6b661b0858bfb16ba8d326 (patch) | |
tree | 2a3dea0bdf43dedba8e040debbd42d7ff17c622f /src | |
parent | bff2ac56b6c5cc969a5219c5a5bf608439436983 (diff) |
Dynmically generate ~/.gitconfig
Ancient versions of 'git' would use the unix passwd identity as the
default author/committer. This dynamically-generated ~/.gitconfig
does the same.
Might as well set excludesfile = ~/.config/git/ignore
Diffstat (limited to 'src')
-rwxr-xr-x | src/gitconfig.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/gitconfig.sh b/src/gitconfig.sh new file mode 100755 index 0000000..3a7e824 --- /dev/null +++ b/src/gitconfig.sh | |||
@@ -0,0 +1,29 @@ | |||
1 | #!/bin/sh | ||
2 | target=~/.gitconfig | ||
3 | if [ -z "$OVERWRITE_GITCONFIG" ] && [ -e "$target" ] | ||
4 | then | ||
5 | exit | ||
6 | fi | ||
7 | |||
8 | user=$(id -un) || exit | ||
9 | [ "$user" ] || exit | ||
10 | email=${user}@$(hostname --fqdn) || exit | ||
11 | [ "$email" ] || exit | ||
12 | name=$(getent passwd "$user" | cut -d: -f2) || : ok | ||
13 | temp=$(mktemp ~/.gitconfig.tmp.XXX) || exit | ||
14 | [ "$temp" ] || exit | ||
15 | |||
16 | gitconfig() | ||
17 | { | ||
18 | cat <<END | ||
19 | [user] | ||
20 | email = ${email} | ||
21 | name = ${name:-$email} | ||
22 | [core] | ||
23 | excludesfile = ~/.config/git/ignore | ||
24 | END | ||
25 | } | ||
26 | |||
27 | gitconfig > "$temp" && | ||
28 | mv "$temp" "$target" || | ||
29 | rm -f "$temp" | ||