#! /bin/bash -
############################
# .make.sh
# This script creates symlinks from the home directory to any desired dotfiles in ~/Dotfiles
############################

########## Variables

dir=~/Dotfiles                                                  # dotfiles directory
olddir=~/Dotfiles_old                                           # old dotfiles backup directory
# list of files/folders to symlink in homedir
files="bash_profile vimrc bashrc inputrc gitconfig gitignore_global vim"

##########

# create dotfiles_old in homedir
echo "Creating $olddir for backup of any existing Dotfiles in ~"
mkdir -p "$olddir"
sleep 1
echo "...done"
echo

# change to the dotfiles directory
echo "Changing to the $dir directory"
cd "$dir"
sleep 1
echo "...done"
echo

# move any existing dotfiles in homedir to dotfiles_old directory, then create symlinks
for file in $files; do
    echo "Moving .$file from ~ to $olddir"
    mv ~/."$file" "$olddir"/"$file"
    sleep 1
    echo "Creating symlink to $file in home directory."
    ln -s "$dir"/"$file" ~/."$file"
    sleep 1
    echo "Finished $file"
    sleep 1
    echo
done

echo "...done"

#! /bin/bash -
############################
# .make.sh
# This script creates symlinks from the home directory to any desired dotfiles in ~/Dotfiles
############################

########## Variables

dir=~/Dotfiles                                                  # dotfiles directory
olddir=~/Dotfiles_old                                           # old dotfiles backup directory
# list of files/folders to symlink in homedir
files="bash_profile vimrc bashrc inputrc gitconfig gitignore_global vim"

##########

# create dotfiles_old in homedir
echo "Creating $olddir for backup of any existing Dotfiles in ~"
mkdir -p "$olddir"
sleep 1
echo "...done"
echo

# clean out dotfiles_old
echo "Cleaning out $olddir to hold fresh backups"
find ~/Dotfiles_old/ -not -path ~/Dotfiles_old/ -delete
sleep 1
echo "...done"
echo

# change to the dotfiles directory
echo "Changing to the $dir directory"
cd "$dir"
sleep 1
echo "...done"
echo

# move any existing dotfiles in homedir to dotfiles_old directory, then create symlinks
for file in $files; do
    echo "Moving .$file from ~ to $olddir"
    mv ~/."$file" "$olddir"/"$file"
    sleep 1
    echo "Creating symlink to $file in home directory."
    ln -s "$dir"/"$file" ~/."$file"
    sleep 1
    echo "Finished $file"
    sleep 1
    echo
done

echo "...done"

Clean backups before remaking symlinks
Clean backups before remaking symlinks

Previously, old backups were simply overwritten, which actually caused a
problem when mv ~/.vim to ~/Dotfiles_old/vim, because the destination
existed, was a directory, and was frequently symlinked into ~/Dotfiles!

This would only noticeably occur if you executed setup/makesymlinks
successively without cleaning out the backups first, so it was not
caught 'til now. It is, however, fixed.

If you wish to preserve those backups, you should do so before running
setup/makesymlinks or ./bootstrap.sh.
