Skip to content

Instantly share code, notes, and snippets.

@mfaerevaag
Last active April 20, 2018 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfaerevaag/6f81eb5aab8412dc1e5d1698d6abfb04 to your computer and use it in GitHub Desktop.
Save mfaerevaag/6f81eb5aab8412dc1e5d1698d6abfb04 to your computer and use it in GitHub Desktop.
Import dot files
#!/usr/bin/sh
REPO="https://github.com/mfaerevaag/dots.git"
DIR="$HOME/.dots"
BACKUP="$HOME/.dots-backup"
function dots {
/usr/bin/git --git-dir=$DIR --work-tree=$HOME $@
}
# clone
git clone -b bare --single-branch --bare $REPO $DIR
# import
dots checkout
# check if existing
if [ $? -eq 0 ]; then
echo "Checked out dots"
else
echo "Backing up pre-existing dot files..."
mkdir -p $BACKUP
dots checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} $BACKUP/{}
if dots checkout; then
echo "Checked out dots"
else
echo "Something failed"
fi
fi
# ignore untracked files
dots config status.showUntrackedFiles no
# clean up
unset REPO
unset DIR
unset BACKUP
@mfaerevaag
Copy link
Author

mfaerevaag commented Apr 20, 2018

Install with

curl -Ls https://gist.github.com/mfaerevaag/6f81eb5aab8412dc1e5d1698d6abfb04/raw/ | /bin/bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment