Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add backup logic to main script #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down