From c74bce5532f69d85802ce0507636d7149f35551c Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Fri, 3 Nov 2023 21:56:22 +0000 Subject: [PATCH] Handle the .gitconfig-* files in .bashrc. --- .bashrc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.bashrc b/.bashrc index 1b8c05d..8f7bc1e 100644 --- a/.bashrc +++ b/.bashrc @@ -558,6 +558,26 @@ hash ssh ssh-add >/dev/null 2>&1 && ssh() { command "${_EXEC:-${FUNCNAME[0]}}" "$@" } +# Handle the ~/.gitconfig link. +if [[ -e "$HOME/.gitconfig-$USER@$HOSTNAME" ]]; then + FILENAME=".gitconfig-$USER@$HOSTNAME" +elif [[ -e "$HOME/.gitconfig-$USER@*.${HOSTNAME#*.}" ]]; then + FILENAME=".gitconfig-$USER@*.${HOSTNAME#*.}" +elif [[ -e "$HOME/.gitconfig-$USER@*" ]]; then + FILENAME=".gitconfig-$USER@*" +elif [[ -e "$HOME/.gitconfig-*@$HOSTNAME" ]]; then + FILENAME=".gitconfig-*@$HOSTNAME" +elif [[ -e "$HOME/.gitconfig-*.${HOSTNAME#*.}" ]]; then + FILENAME=".gitconfig-*.${HOSTNAME#*.}" +elif [[ -e "$HOME/.gitconfig-default" ]]; then + FILENAME=".gitconfig-default" +else + (cd "$HOME" && [[ -L ".gitconfig" ]] && rm -f ".gitconfig") + printf "%s: %s\\n" "${BASH_SOURCE##*/}" "failed to update .gitconfig symlink" >&2 +fi +[[ -n "$FILENAME" ]] && (cd "$HOME" && ln -sf "$FILENAME" ".gitconfig") +unset FILENAME + # Platform specific set up. if [[ "$PLATFORM" = "Linux" ]]; then # Linux specific functions.