dotfiles/.bash_profile.d/gitconfig

21 lines
899 B
Bash

#!/bin/bash - not strictly necessary, but helps nano with syntax highlighting.
# Symlink the .gitconfig file to the most specific .gitconfig-* file.
if [[ -e "$HOME/.gitconfig-$USER@$HOSTNAME" ]]; then
FILE=".gitconfig-$USER@$HOSTNAME"
elif [[ -e "$HOME/.gitconfig-$USER@*.${HOSTNAME#*.}" ]]; then
FILE=".gitconfig-$USER@*.${HOSTNAME#*.}"
elif [[ -e "$HOME/.gitconfig-$USER@*" ]]; then
FILE=".gitconfig-$USER@*"
elif [[ -e "$HOME/.gitconfig-*@$HOSTNAME" ]]; then
FILE=".gitconfig-*@$HOSTNAME"
elif [[ -e "$HOME/.gitconfig-*.${HOSTNAME#*.}" ]]; then
FILE=".gitconfig-*.${HOSTNAME#*.}"
elif [[ -e "$HOME/.gitconfig-default" ]]; then
FILE=".gitconfig-default"
else
(cd "$HOME" && [[ -L ".gitconfig" ]] && rm -f ".gitconfig")
printf "%s: %s\\n" "${BASH_SOURCE##*/}" "failed to update .gitconfig symlink" >&2
fi
[[ -n "$FILE" ]] && (cd "$HOME" && ln -sf "$FILE" ".gitconfig")
unset FILE