Skip to content

Instantly share code, notes, and snippets.

@conrad784
Last active March 25, 2018 11:16
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 conrad784/25be530c86c77a508119b0adef320a52 to your computer and use it in GitHub Desktop.
Save conrad784/25be530c86c77a508119b0adef320a52 to your computer and use it in GitHub Desktop.
bootstrap config files
#!/bin/sh
# found here: https://developer.atlassian.com/blog/2016/02/best-way-to-store-dotfiles-git-bare-repo/
# tried to improve to work with subfolders, but something is wrong, sometimes have to run twice
git clone --bare git@github.com:conrad784/dotfiles.git $HOME/.cfg
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
function mv_fullpath(){
copy_file="$1";
#echo "cf: $copy_file";
to_file="$2";
#echo "tf: $to_file";
to_path="$( dirname ${to_file} )";
#echo "tp: $to_path";
mkdir -p $to_path;
#echo "mv: $copy_file $to_path";
mv $copy_file $to_path;
#echo ""
}
mkdir -p .config-backup
config checkout
if [ $? = 0 ]; then
echo "Checked out config.";
else
echo "Backing up pre-existing dot files.";
FILES=$( config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} )
for x in $FILES;
do
echo "moving $x"
mv_fullpath $x .config-backup/$x;
done
echo "Finished backing up.";
fi;
config checkout
config config status.showUntrackedFiles no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment