51 lines
1.8 KiB
Bash
Executable File
51 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
## DOWNLOADED FROM GIT REPO ##
|
|
|
|
# Find all dot files then if the original file exists, create a backup
|
|
# Once backed up to {file}.dtbak symlink the new dotfile in place
|
|
for file in $(find . -maxdepth 1 -name ".*" -type f -printf "%f\n"); do
|
|
# Check if it's a file and if a symlink already exists
|
|
target_file="~/$file"
|
|
if [ -e $target_file ]; then
|
|
if [ -L $target_file ]; then
|
|
# If it's a symlink and points to the correct location, skip it
|
|
target_link=$(readlink $target_file)
|
|
if [ "$target_link" != "$PWD/$file" ]; then
|
|
mv -f $target_file{,.dtbak} # Backup existing symlink or file
|
|
fi
|
|
else
|
|
mv -f $target_file{,.dtbak} # Backup if it's not a symlink
|
|
fi
|
|
fi
|
|
ln -s $PWD/$file $target_file
|
|
done
|
|
|
|
# Handle directories
|
|
for dir in $(find . -maxdepth 1 -name ".*" -type d); do
|
|
target_dir="~/$dir"
|
|
|
|
# Create the directory in the target location if it doesn't exist
|
|
if [ ! -d $target_dir ]; then
|
|
mkdir -p $target_dir
|
|
fi
|
|
|
|
# Now handle symlinks for files inside the directory
|
|
for subfile in $(find $dir -type f); do
|
|
relative_subfile="${subfile#$dir/}"
|
|
target_subfile="$target_dir/$relative_subfile"
|
|
|
|
# Check if the symlink already exists and points to the correct location
|
|
if [ ! -e $target_subfile ]; then
|
|
ln -s $PWD/$subfile $target_subfile
|
|
elif [ -L $target_subfile ]; then
|
|
target_link=$(readlink $target_subfile)
|
|
if [ "$target_link" != "$PWD/$subfile" ]; then
|
|
mv -f $target_subfile{,.dtbak} # Backup existing symlink
|
|
ln -s $PWD/$subfile $target_subfile # Create new symlink
|
|
fi
|
|
fi
|
|
done
|
|
done
|
|
|