Last active
October 13, 2018 00:59
-
-
Save reed-jones/ddacd4b0df3f56dca824b80198c66255 to your computer and use it in GitHub Desktop.
Restores previous dotfiles in a bare repo
This file contains hidden or 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/bash | |
# passing arguments to curl | |
# curl http://foo.com/script.sh | bash -s arg1 arg2 | |
args=("$@") | |
if [ $# -ne 1 ]; then | |
echo "Script must be passed a git repo containing dotfiles"; | |
echo "e.g. ./dotfile-init.sh https://gitlab.com/reed-jones/dotfiles.git"; | |
exit 1; | |
fi; | |
git clone --bare ${args[0]} $HOME/.dotfiles; | |
function dotfiles { | |
/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME $@; | |
} | |
dotfiles checkout | |
if [ $? -eq 0 ]; then | |
echo "Checked out config"; | |
else | |
echo "Backing up pre-existing dotfiles."; | |
mkdir -p $HOME/.config-backup | |
dotfiles checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{} | |
fi | |
dotfiles checkout | |
dotfiles config status.showUntrackedFiles no |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment