dotfiles/symlink.sh

30 lines
694 B
Bash
Executable file

#!/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