Skip to content

Instantly share code, notes, and snippets.

@anson-vandoren
Last active November 27, 2019 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anson-vandoren/adb48de6130eeacf27ec8f545d839cf6 to your computer and use it in GitHub Desktop.
Save anson-vandoren/adb48de6130eeacf27ec8f545d839cf6 to your computer and use it in GitHub Desktop.
Private configuration for dotfiles
GIT_AUTHOR_NAME="Your Name"
GIT_AUTHOR_EMAIL="your.email@address.com"
# if there is no username set, set it now
if ! git config --list | grep -q "user.name"; then
git config --file ~/.gitconfig_private user.name "$GIT_AUTHOR_NAME"
fi
# if there is no user email set, set it now
if ! git config --list | grep -q "user.email"; then
git config --file ~/.gitconfig_private user.email "$GIT_AUTHOR_EMAIL"
fi
# if there is no signing key set, try to set it now with user permission
if ! git config --list | grep -q "user.signingkey"; then
# get gpg signing key
keyid_regex="sec.+rsa4096/([^ ]+)"
keys=$(gpg --list-secret-keys --keyid-format long)
signingKey=$(echo $keys | grep -Ei "sec.+rsa4096/([^ ]+)" | cut -d / -f 2 | cut -d ' ' -f 1)
echo "Found gpg keys below"
echo $keys
echo "keyId $signingKey will be used for git."
echo "Is this OK? (y/n)"
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
git config --file ~/.gitconfig_private user.signingkey $signingKey
echo "Set signing key"
else
echo "Did not set signing key"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment