Last active
May 3, 2025 10:23
-
-
Save TA-Solaris/ec60784b65710d289b895857d673cde7 to your computer and use it in GitHub Desktop.
A script for installing my dotfiles
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 | |
| 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