Created
December 17, 2024 21:59
-
-
Save Luis-Henriquez-Perez/23978c50db3c65878f0f945b582ea354 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Variables | |
DOTFILE_URL=https://github.com/Luis-Henriquez-Perez/dotfiles | |
DOTFILE_DIR=$HOME/.dotfiles | |
# Clone the dotfiles repository as a bare repo | |
git clone --bare $DOTFILE_URL $DOTFILE_DIR | |
# Function to interact with the bare Git repository | |
dot() { | |
/usr/bin/git --git-dir=$DOTFILE_DIR --work-tree=$HOME "$@" | |
} | |
# Create a backup directory for pre-existing dotfiles | |
mkdir -p .config-backup | |
# Try to check out the files | |
if dot checkout; then | |
echo "Checked out config."; | |
else | |
echo "Backing up pre-existing dot files."; | |
# Find existing files that conflict and move them to the backup directory | |
dot checkout 2>&1 | egrep "\s+\." | awk '{print $1}' | while read -r file; do | |
mv "$HOME/$file" "$HOME/.config-backup/$file" | |
done | |
# Retry the checkout | |
dot checkout | |
fi | |
# Configure the repository to ignore untracked files | |
dot config status.showUntrackedFiles no |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment