Skip to content

Instantly share code, notes, and snippets.

@tulexx
Last active August 31, 2020 18:53
Show Gist options
  • Save tulexx/522cf813352dd1948ae3b52ba7a4c600 to your computer and use it in GitHub Desktop.
Save tulexx/522cf813352dd1948ae3b52ba7a4c600 to your computer and use it in GitHub Desktop.
Install dotfiles
#!/usr/bin/env bash
shopt -s expand_aliases
DOTFILES_DIR="$HOME/.dotfiles"
BACKUP_DIR="$HOME/dotfiles.bak"
if [ ! -d "$DOTFILES_DIR" ]; then
echo "Cloning dotfiles"
git clone --bare -q git@github.com:tulexx/.dotfiles.git "$DOTFILES_DIR"
fi
alias dotfiles="/usr/bin/git --git-dir=\$DOTFILES_DIR --work-tree=\$HOME"
dotfiles config --local status.showUntrackedFiles no
dotfiles checkout 2> /dev/null
if [ "$(dotfiles checkout 2> /dev/null)" ]; then
echo "Checked out dotfiles"
else
echo "Backing up old files"
mkdir -p "$BACKUP_DIR"
dotfiles checkout 2>&1 | awk '/\s+\./ { print $1 }' | xargs -I{} rsync -aqzhR --remove-source-files {} "$BACKUP_DIR/"
dotfiles checkout
echo "Backed up old files in $BACKUP_DIR and checked out"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment