Last active
December 2, 2023 00:12
-
-
Save Fraetor/059207afa6a1791f480586cf52b19a76 to your computer and use it in GitHub Desktop.
Installation script for my dotfiles.
This file contains 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/sh | |
set -eu | |
IFS="$(printf '\n\t')" | |
# Ask what repository to clone. | |
printf 'Dotfiles repository URL [git@github.com:Fraetor/dotfiles.git]: ' | |
read -r repo | |
if [ -z "$repo" ] | |
then | |
repo='git@github.com:Fraetor/dotfiles.git' | |
fi | |
git clone --bare "$repo" "$HOME/.dotfiles" | |
# Setup git alias. | |
dotfile() { | |
/usr/bin/git --git-dir="$HOME/.dotfiles/" --work-tree="$HOME" "$@" | |
} | |
# Ask what branch to checkout. | |
printf 'What branch do you want? [main]: ' | |
read -r branch | |
if [ -z "$branch" ] | |
then | |
branch='main' | |
fi | |
if [ -z "$(dotfile branch --list "$branch")" ] | |
then | |
echo "No branch found called $branch" | |
exit 1 | |
fi | |
# Try checking out, and move conflicting dotfiles if they conflict. | |
if dotfile checkout "$branch" | |
then | |
echo "Checked out dotfiles." | |
else | |
echo "Backing up pre-existing files" | |
# awk is getting the first column here. | |
dotfile checkout 2>&1 | grep -E "\s+\." | awk '{print $1}' | xargs -I{} mv -v {} {}.backup | |
fi | |
# Does nothing if already checked out, but will error nicely if can't. | |
dotfile checkout "$branch" | |
# Other setup bits and bobs. | |
printf '\n*\n' >> "$HOME/.dotfiles/info/exclude" | |
dotfile config --local status.showUntrackedFiles no | |
echo "All done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment