Skip to content

Instantly share code, notes, and snippets.

@anydef
Last active March 5, 2023 00:27
Show Gist options
  • Save anydef/b301cc960110221738b4fc7a3666835d to your computer and use it in GitHub Desktop.
Save anydef/b301cc960110221738b4fc7a3666835d to your computer and use it in GitHub Desktop.
Configure
#!/bin/bash
set -x
## Rip-off Nicola Paolucci article -> https://www.atlassian.com/git/tutorials/dotfiles
## Read repo
REPO="git@github.com:anydef/dotfiles.git"
## Setup aliases for dotfile bare repo and pull configs from git.
## Ignore .cfg to avoid possible recursion issues.
echo ".cfg" >> .gitignore
## Clone dotfiles
mkdir -p .cfg
git clone --bare $REPO $HOME/.cfg
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
## Attempt to clone. Might as well fail.
config checkout
## Backup existing dotfiles if prev failed.
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;
## Checkout once again
config checkout
## Configure files tracking
config config --local status.showUntrackedFiles no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment