I'm doing the git dot files thing and created a script -- my first Unix shell script -- to synchronise the repo dot files with those in the user's home. It checks which dot files exist in the repo folder (except for .git) and then archives any clashes in the home directory before symlinking to the repo... I wrote this largely by experimentation and Googling. It works, but I'm just checking to see if there's anything I missed or if there are better solutions?
#!/bin/sh
# Archive existing dot files and symlink to the new ones
# Run from ~/dotfiles
# All dot files apart from .git, . and ..
dotFiles=(`ls -da .* | grep -Pxv '\.git|\.+'`)
# Existing dot files to archive
toArchive=()
cd ~
# Archive: Find clashes and tarball+gzip them
for i in ${dotFiles[*]}; do
toArchive=(${toArchive[@]} `ls -d $i`)
done
if [ ${#toArchive[*]} != 0 ]; then
archiveFile="dotfiles"`date +%Y%m%d`".tar.gz"
tar czf $archiveFile ${toArchive[*]} --remove-files
fi
# Create symlinks
for i in ${dotFiles[*]}; do
dotFileLink="dotfiles/"$i
ln -s $dotFileLink $i
done