Skip to content

Instantly share code, notes, and snippets.

@w0ltage
Created August 18, 2023 07:47
Show Gist options
  • Save w0ltage/f64e3e29cc9d352e4eef8a7f2c7132c0 to your computer and use it in GitHub Desktop.
Save w0ltage/f64e3e29cc9d352e4eef8a7f2c7132c0 to your computer and use it in GitHub Desktop.
Install dotfiles from git bare repository
#!/bin/bash
# inspired by https://www.atlassian.com/git/tutorials/dotfiles
[ $# -eq 0 ] && { echo "Usage: $0 <remote-repo-url>"; exit 1; }
REMOTE_REPO=$1
BARE_REPO_PATH=$HOME/.dotfiles
git clone --bare $REMOTE_REPO $BARE_REPO_PATH
function config {
/usr/bin/git --git-dir=$BARE_REPO_PATH --work-tree=$HOME $@
}
mkdir -p $HOME/.config-backup
config checkout
if [ $? = 0 ]; then
echo "Checked out config.";
else
echo "Backing up pre-existing dot files.";
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{}
fi;
config checkout
config config status.showUntrackedFiles no
printf "\nDotfiles installed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment