Changed dotfile location and made path concatenation more robust.
This commit is contained in:
@@ -1,23 +1,28 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# config directory
|
# config directory
|
||||||
config_dir="$HOME/config/"
|
config_dir="$HOME/dotfiles/"
|
||||||
|
|
||||||
# backup directory, files that would otherwise be overwritten go there
|
# backup directory, files that would otherwise be overwritten go there
|
||||||
backup_dir="$HOME/oldconfig/"
|
backup_dir="$HOME/dotfiles.bak/"
|
||||||
|
|
||||||
# the following folders inside $config_dir will be inspected and symlinked:
|
# the following folders inside $config_dir will be inspected and symlinked:
|
||||||
symlink_folders="bash git i3 vim zsh"
|
symlink_folders="bash git i3 vim zsh"
|
||||||
|
|
||||||
|
path_combine()
|
||||||
|
{
|
||||||
|
echo "$(dirname "$1")/$(basename "$1")/$(basename "$2")"
|
||||||
|
}
|
||||||
|
|
||||||
# backup the old config files
|
# backup the old config files
|
||||||
backup_dir="$backup_dir/$(date +%Y-%m-%dT%H:%M:%S)"
|
backup_dir="$backup_dir/$(date +%Y-%m-%dT%H:%M:%S)"
|
||||||
echo "Backing up old configuration files into \"$backup_dir\"."
|
echo "Backing up old configuration files into \"$backup_dir\"."
|
||||||
mkdir -p "$backup_dir"
|
mkdir -p "$backup_dir"
|
||||||
for folder in $symlink_folders ; do
|
for folder in $symlink_folders ; do
|
||||||
for file in "$config_dir/$folder"/* ; do
|
for file in "$(path_combine "$config_dir" "$folder")"/* ; do
|
||||||
oldfile="$HOME/.$(basename "$file")"
|
oldfile="$(path_combine "$HOME" ".$(basename "$file")")"
|
||||||
if [[ -e "$oldfile" ]] ; then
|
if [[ -e "$oldfile" ]] ; then
|
||||||
destination="$backup_dir/$(basename "$oldfile")"
|
destination="$(path_combine "$backup_dir" "$(basename "$oldfile")")"
|
||||||
echo "mv: \"$oldfile\" -> \"$destination\""
|
echo "mv: \"$oldfile\" -> \"$destination\""
|
||||||
mv "$oldfile" "$destination"
|
mv "$oldfile" "$destination"
|
||||||
else
|
else
|
||||||
@@ -29,10 +34,10 @@ done
|
|||||||
# now symlink the files in $config_dir into the home directory
|
# now symlink the files in $config_dir into the home directory
|
||||||
echo "Creating symlinks for configuration files in \"$config_dir\"."
|
echo "Creating symlinks for configuration files in \"$config_dir\"."
|
||||||
for folder in $symlink_folders ; do
|
for folder in $symlink_folders ; do
|
||||||
for file in "$config_dir/$folder"/* ; do
|
for file in "$(path_combine "$config_dir" "$folder")"/* ; do
|
||||||
destination="$HOME/.$(basename "$file")"
|
destination="$(path_combine "$HOME" ".$(basename "$file")")"
|
||||||
echo "ln -s \"$file\" -> \"$destination\""
|
echo "ln -sf \"$file\" -> \"$destination\""
|
||||||
ln -s "$file" "$destination"
|
ln -sf "$file" "$destination"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user