diff --git a/install.sh b/install.sh index 1eae8138..3cb90b05 100755 --- a/install.sh +++ b/install.sh @@ -10,6 +10,13 @@ # dotfiles directory dotfiledir="${HOME}/dotfiles" +# Create the backup directory if it doesn't exist +currentdate=$(date +%Y-%m-%d) +backupdir="${HOME}/dotfiles/backups/${currentdate}" + +mkdir -p "${backupdir}" +echo "Backup dir created" + # list of files/folders to symlink in ${homedir} files=(zshrc zprofile zprompt bashrc bash_profile bash_prompt aliases private) @@ -19,6 +26,12 @@ cd "${dotfiledir}" || exit # create symlinks (will overwrite old dotfiles) for file in "${files[@]}"; do + if [ -e "${HOME}/.${file}" ]; then + # Backup existing files to the backup directory + echo "Backing up $file to ${backupdir}" + cp "${HOME}/.${file}" "${backupdir}/" + fi + echo "Creating symlink to $file in home directory." ln -sf "${dotfiledir}/.${file}" "${HOME}/.${file}" done