diff --git a/symlink.sh b/symlink.sh new file mode 100755 index 0000000..32e887d --- /dev/null +++ b/symlink.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Creates symlinks from home to ~/dotfiles + +#Variables +dir=~/dotfiles +olddir=~/oldConfig +files="$(find . -type f ! -path './.git/*' ! -name 'symlink.sh' -printf '%P\n')" + +timestamp="$(date +%s)" + +#Create oldConfig in ~ + +mkdir -p $olddir/$timestamp +echo "Created $olddir/$timestamp to backup existing dotfiles in ~" + +#Swap dir +cd $dir + +# Move any existing config-files to $olddir and then creating symlinks +for file in $files; do + echo "Backing up old configuration files" + mkdir -p $olddir/$timestamp/$(dirname $file) + mv ~/.$file $olddir/$timestamp/$file + + echo "Creating symlink from homedir to $file." + mkdir -p $(dirname ~/.$file) + ln -s $dir/$file ~/.$file + echo "Done." +done