Files
dotfiles/scripts/makesymlinks.bash

44 lines
1.4 KiB
Bash
Raw Normal View History

2013-09-14 14:35:23 +02:00
#!/usr/bin/env bash
# config directory
config_dir="$HOME/dotfiles/"
2013-09-14 14:35:23 +02:00
# backup directory, files that would otherwise be overwritten go there
backup_dir="$HOME/dotfiles.bak/"
2013-09-14 14:35:23 +02:00
# the following folders inside $config_dir will be inspected and symlinked:
symlink_folders="bash git i3 vim zsh"
path_combine()
{
echo "$(dirname "$1")/$(basename "$1")/$(basename "$2")"
}
2013-09-14 14:35:23 +02:00
# backup the old config files
backup_dir="$backup_dir/$(date +%Y-%m-%dT%H:%M:%S)"
echo "Backing up old configuration files into \"$backup_dir\"."
mkdir -p "$backup_dir"
for folder in $symlink_folders ; do
for file in "$(path_combine "$config_dir" "$folder")"/* ; do
oldfile="$(path_combine "$HOME" ".$(basename "$file")")"
2013-09-14 14:35:23 +02:00
if [[ -e "$oldfile" ]] ; then
destination="$(path_combine "$backup_dir" "$(basename "$oldfile")")"
2013-09-14 14:35:23 +02:00
echo "mv: \"$oldfile\" -> \"$destination\""
mv "$oldfile" "$destination"
else
echo "\"$oldfile\" not found, skipped."
fi
done
done
# now symlink the files in $config_dir into the home directory
echo "Creating symlinks for configuration files in \"$config_dir\"."
for folder in $symlink_folders ; do
for file in "$(path_combine "$config_dir" "$folder")"/* ; do
destination="$(path_combine "$HOME" ".$(basename "$file")")"
echo "ln -sf \"$file\" -> \"$destination\""
ln -sf "$file" "$destination"
2013-09-14 14:35:23 +02:00
done
done