Skip to content

Instantly share code, notes, and snippets.

@TA-Solaris
Last active May 3, 2025 10:23
Show Gist options
  • Select an option

  • Save TA-Solaris/ec60784b65710d289b895857d673cde7 to your computer and use it in GitHub Desktop.

Select an option

Save TA-Solaris/ec60784b65710d289b895857d673cde7 to your computer and use it in GitHub Desktop.
A script for installing my dotfiles
#!/bin/bash
set -e
REPO="git@github.com:TA-Solaris/dotfiles.git"
DOTFILES_DIR="$HOME/dotfiles"
# Step 1: Configure Git identity
git config --global user.name "Edward Potter"
git config --global user.email "pottered2@gmail.com"
# Step 2: Generate SSH key if not present
if [ ! -f "$HOME/.ssh/id_ed25519" ]; then
echo "πŸ”‘ Generating SSH key..."
ssh-keygen -t ed25519 -C "pottered2@gmail.com" -f "$HOME/.ssh/id_ed25519" -N ""
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
else
echo "βœ… SSH key already exists."
fi
# Step 3: Show public key and prompt user to add to GitHub
echo "πŸ“‹ Your public SSH key is:"
cat "$HOME/.ssh/id_ed25519.pub"
echo "πŸ”— Add this key to GitHub: https://github.com/settings/ssh/new"
read -p "Press enter to continue when done..."
# Step 4: Only clone if not already present
if [ ! -d "$DOTFILES_DIR" ]; then
echo "πŸ“¦ Cloning dotfiles repo as a bare repo..."
echo "dotfiles" >> "$HOME/.gitignore"
git clone --bare "$REPO" "$DOTFILES_DIR"
else
echo "βœ… Dotfiles repo already exists at $DOTFILES_DIR"
fi
# Step 5: Define config alias
config() {
/usr/bin/git --git-dir="$HOME/dotfiles/" --work-tree="$HOME" "$@"
}
# Step 6: Attempt to check out dotfiles
echo "πŸ“ Attempting to check out dotfiles into ~"
if ! config checkout; then
echo "⚠️ Conflicts detected. Backing up conflicting files..."
mkdir -p "$HOME/.config-backup"
conflicts=$(config checkout 2>&1 | grep -E "\s+\." | awk '{print $1}')
for file in $conflicts; do
src="$HOME/$file"
dest="$HOME/.config-backup/$file"
mkdir -p "$(dirname "$dest")"
mv "$src" "$dest"
echo "πŸ” Moved $src to $dest"
done
echo "πŸ” Retrying checkout..."
config checkout
fi
# Step 7: Hide untracked files
config config --local status.showUntrackedFiles no
echo "βœ… Dotfiles setup complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment